Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Button - Who am I? 1

Status
Not open for further replies.

faithful1

Programmer
Sep 27, 2002
49
US
Hello...I have created some dynamic buttons and a click event, however, I am having problems distinguishing which button was clicked. How can I display the name of the button that was clicked?

Here is my sample code of the button created and the addhandler event.
Thank you in advance!!!!!!

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim pageNumber As New Button()
Session("recordsPerPage") = 10
Session("totalPages") = Int(Session("totalrecords") / Session("recordsPerPage"))
If (Session("totalrecords") Mod Session("recordsPerPage")) > 0 Then
Session("totalPages") = Session("totalPages") + 1
End If

For i = 1 To Session("totalPages")
pageNumber = New Button()
pageNumber.Text = i
pageNumber.ID = "page" + i.ToString
AddHandler pageNumber.Click, AddressOf PageNumber_OnClick
pagesPlaceHolder.Controls.Add(pageNumber)
Response.Write("  ")
Next
End Sub

Private Sub PageNumber_OnClick(ByVal sender As Object, _
ByVal e As System.EventArgs)
Response.Write("This is the click event")

End Sub

***I need to use the id of the item clicked to run a query, so I need to find out how to tell which button was clicked.


 
Hi Faithful1,

In your PageNumber_OnClick routine you could use something like:

Code:
'This would give you the Button's name.
Dim sButtonName As String = CType(sender, Button).Name

'Or maybe this, which would give the numerical value of the Button's Tag property.
Dim sTag As Int32 = CInt(CType(sender, Button).Tag)

Obviously mess around with the code to suit your needs.

T0AD

There's a thin line between genius, and insanity!
 
You are absolutely Amazing! Thank you for your Help!!
One star for you!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top