I am trying to add a button to my ascx page and do some functionalities. But the button OnClick not firing. So, please advise me on how to access the button click method. Thank you
ascx page:
<asp:Button ID="btnEncryptNIN" runat="server" Text="Encrypt" OnClick="btnEncryptNIN_Click"/>
ascx.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Url.ToString().Contains("printreportingchart.aspx"))
{
lblEmpNumber.Style.Add("display", "none");
lblEmpNumber1.Style.Add("display", "none");
//miniProfile.InnerText = "";
}
}
protected void btnEncryptNIN_Click(object sender, EventArgs e)
{
string name = "s";
}
It sounds like the
Clickevent is not wired up to the controlbtnEncryptNINserver control. There are a couple of ways to solve this. You can addAutoEventWireup="true"as an additional attribute to the<%@ Control %>on the first line of the ascx file. OR you can add the linebtnEncryptNIN.Click += BtnEncryptNIN_Click;into the Page_Load method in the ascx.cs code behind file