firing events

G

Guest

hi all
i need to fire a click events of a button that i add at run time what can i
do??
i need to get a property value of other controls that i add also at runtime
i want to get this property when i click this button
any ideas ??
thanks
 
K

Kumar Reddi

You need to add an event handler to the click event of the Button, lets say
your button's id is "Button1",

Button1.Click +=new EventHandler(Button1_Click);

where Button1_Click can be substitued with any other method you want, which
has the same signature as the typical button click event handler has

Good Luck
 
K

Ken Cox [Microsoft MVP]

Hi Sara,

You need to use AddHandler to create the event and Page.FindControl to get
a reference to the control on the page.

To fire an event, you just call it:
http://msdn.microsoft.com/library/d...en-us/vblr7/html/vastmAddHandlerStatement.asp

Some sample code below. Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


Public btnOK As Button
Public lblResult As Label
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
btnOK = New Button
btnOK.ID = "btnOK"
btnOK.Text = "OK"
btnOK.ToolTip = "Click Me!"
AddHandler btnOK.Click, AddressOf ClickHandler
PlaceHolder1.Controls.Add(btnOK)

lblResult = New Label
lblResult.ID = "lblResult"
PlaceHolder1.Controls.Add(lblResult)
End Sub

Private Sub ClickHandler _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Dim btnTemp As Button
Dim lblTemp As Label
lblTemp = Page.FindControl("lblResult")
btnTemp = sender
lblTemp.Text = btnTemp.ID
End Sub


<form id="Form1" method="post" runat="server">
<asp:placeholder id="PlaceHolder1"
runat="server"></asp:placeholder>
</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top