Dynamically loaded user control's button event firing problem [modified]

jophin

New member
Joined
Jun 4, 2008
Messages
4
Programming Experience
Beginner
Hi ,
I am having a page in which I am dynamically loading a usercontrol on click of LoadUserControl button . On click of the LoadUserControl button the user control is loaded dynamically . In the user control one update button is there . On click of the update button , the update button event is firing . After that we again load this user control by clicking the LoadUserControl button . Then if we click on the update button of the user control the update button event is not firing . Please help .
Thanks in advance
Jophin
 
You need to delegate an event everytime you dynammically load this control.
VB.NET:
'assuming you have a panel in your webpage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 
    Dim b As New Button() 
    AddHandler b.Click, AddressOf handler 
    b.Text = "Sample" 
    Panel1.Controls.Add(b) 
    
End Sub 
Private Sub handler(ByVal sender As Object, ByVal e As EventArgs) 
    Dim b As Button = DirectCast(sender, Button) 
    Response.Write(b.Text + " button is clicked!") 
End Sub
 
Last edited by a moderator:
Back
Top