Click here to Skip to main content
15,881,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,


IS it possible to call all event of usercontrol which loaded dynamically on page?

I have loaded usercontrol on button_click event.
i.e.
My scenario is:
not any event called of usercontrol,i want to called button_click event of usercontrol but its not called.

I have google it and applied solution but my problem have not fixed.

Please suggest me answer.
Posted
Comments
Devang Vaja 6-Dec-12 6:47am    
have You made the usercontrol.ascx for that control?? desale Ji...?
madhuri@mumbai 6-Dec-12 6:59am    
yah,I have created UC and added it on buttonclick event of aspx page.and UC load proper,
but on UC's event not fired.
Devang Vaja 6-Dec-12 7:01am    
i had the same problem but i got sollution By
below code in my answer

1 solution

C#
declare method  in uc.ascx.cs
 public event EventHandler<eventargs>Click;
public void Btn1_Click(object sender, System.EventArgs e)
   {
       try
       {
           //your logic here          
           this.Click(this.Btn1, e);
        }
       catch (Exception ex)
       {
       }
   }
and Main thing is that
 <asp:button id="btn1" runat="server" onclick="btn1_Click" />

write Button Onclick in design side
 
Share this answer
 
v4
Comments
madhuri@mumbai 6-Dec-12 7:27am    
and in aspx page how you register event
Devang Vaja 6-Dec-12 7:30am    
<%@ Register Src="AutoCompleteControl.ascx" TagName="AutoCompleteControl" TagPrefix="uc1" %>

i have made autocomplete control using web service...

<uc1:auctcompletecontrol id=DrpName Autopostback="true" runat="server" onTextchanged="DrpName_TextChanged"/>
madhuri@mumbai 6-Dec-12 7:47am    
I am asking about you loading usercontrol dynamically...
Devang Vaja 6-Dec-12 7:51am    
i think u should add eventlistner to your button in codebehind when you load it dynamically... may be that will work:)

Control c1;
c1 = LoadControl("~/test.ascx");
madhuri@mumbai 6-Dec-12 8:31am    
I have solved it,it doesn't need any eventhandler or any eventlistener,but another problem occured.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900