asp.net - Mulitple linkbuttons in user control needs to call event handler in the aspx page -


i have multiple user controls on page , each of them have multiple linkbuttons perform same logic on server side. there way linkbuttons have same event handler defined in code behind of page?

if needed, can change linkbuttons other html or asp.net control long can support clickable image.

inside usercontrol create event , wire up. call linkbuttons onclick event handler:

usercontrol.ascx:

<asp:linkbutton runat="server" id="linkbutton1" onclick="linkbuttonclicked"> click me </asp:linkbutton> <asp:linkbutton runat="server" id="linkbutton2" onclick="linkbuttonclicked"> click me again </asp:linkbutton> 

usercontrol.ascx.cs

public event eventhandler usercontrollinkclick;  protected void linkbuttonclicked(object sender, eventargs e) {    if (this.usercontrollinkclick!= null)        {            this.usercontrollinkclick(this, e);        } } 

inside parent page wire user controls usercontrollinkclick:

protected override void oninit(eventargs e) {     myusercontrol uc = loadcontrol("~/pathtousercontrol.ascx");     uc.usercontrollinkclick += new eventhandler(myusercontrol_usercontrollinkclick); }  protected void myusercontrol_usercontrollinkclick(object sender, eventargs e) {     //this code execute when usercontrol's linkbuttonclicked event fired. } 

hope helps!!


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -