firing events

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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>
 
Back
Top