c# - OnClick not firing in UserControl when button is clicked -
i have master page. in master page have usercontrol footer. in footer have button not firing onclick. during debugging see function being called onclick, btnsignup_click, not getting hit. can't seem figure out mistake in code is.
wanted note validation functionality working correctly.
master.master
<%@ master language="c#" autoeventwireup="true" inherits="master" codebehind="master.master.cs" %> <%@ register tagprefix="xyz" tagname="footer" src="~/controls/footer.ascx" %> <xyz:footer id="footer" runat="server" />
footer.ascx
<%@ control language="c#" autoeventwireup="true" inherits="footer" codebehind="footer.ascx.cs" %> <div> <asp:textbox id="fname" runat="server"></asp:textbox> <asp:requiredfieldvalidator id="requiredfieldvalidatorfname" validationgroup="validationsignup" display="static" controltovalidate="fname" errormessage="first name required" runat="server"></asp:requiredfieldvalidator> </div> <div class="button"> <asp:button id="btnsignup" commandname="button" runat="server" validationgroup="validationsignup" text="signup" headertext="please fill in required fields before continuing." onclick="btnsignup_click"/> </div> <div class="validationsummary"> <asp:validationsummary id="validationsummary" validationgroup="validationsignup" runat="server"></asp:validationsummary> </div>
footer.ascx.cs
public partial class templates_site_footer : baseusercontrol { protected void page_load(object sender, eventargs e) { btnsignup.click += new eventhandler(btnsignup_click); } protected void btnsignup_click(object sender, eventargs e) { if (!page.isvalid) return; // code execute after button clicked } }
remove btnsignup.click += new eventhandler(btnsignup_click);
code page_load event, had assigned onclick
event button in .ascx markup , no need check validate of page again in btnsignup_click
, can directly write button click event code want execute.
your footer user control code behind:
protected void page_load(object sender, eventargs e) { //btnsignup.click += new eventhandler(btnsignup_click); } protected void btnsignup_click(object sender, eventargs e) { if (page.isvalid) { // code execute after button clicked } else { // page not validated. } }
Comments
Post a Comment