How to call button click function in ascx

553 Views Asked by At

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";
            }
1

There are 1 best solutions below

2
pthomson On

It sounds like the Click event is not wired up to the control btnEncryptNIN server control. There are a couple of ways to solve this. You can add AutoEventWireup="true" as an additional attribute to the <%@ Control %> on the first line of the ascx file. OR you can add the line btnEncryptNIN.Click += BtnEncryptNIN_Click; into the Page_Load method in the ascx.cs code behind file