asp.net - How to handle or check User Control postback in Parent page? -
i have checkbox in user control. how disable parent control's event when user control's checkbox's checkedchanged event triggered?
you cannot disable events asp.net life cycle.
however, can check inside each event whether postback triggered parent or user control.
if want check control fire event inside parent page -
public partial class default : page { protected void page_load(object sender, eventargs e) { if (ispostback) { string id = request.form["__eventtarget"]; if (!string.isnullorwhitespace(id) && id.contains("webusercontrol11")) { } } } }
if want check whether event fired 1 of control inside usercontrol -
public partial class webusercontrol1 : system.web.ui.usercontrol { protected void page_load(object sender, eventargs e) { if (ispostback) // *** ispostback not same parent's ispostback *** { } } protected void checkbox1_checkedchanged(object sender, eventargs e) { if (ispostback) { } } }
Comments
Post a Comment