locked
Button Click Not Triggering in Content Page RRS feed

  • Question

  • User1405798523 posted

    Hi,

    I am new to ASP.NET and I in my Project I have a MasterPage with form (runat server) which holds a Content PlaceHolder.

    In my Content Page I have a button and I have not used any form tag within it.

    My Problem is that the Button Click Event is not triggering when I click it.

    To check,I added another Button and the same problem facing again.

    MasterPage

    <form runat="server">

    <div>

    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>

    </div>

    </form>

    Content Page

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

    <b><asp:LinkButton ID="AddRole_Linkbtn" runat="server" OnClick="AddRole_Linkbtn_Click" >+ Add Role</asp:LinkButton></b>

    <asp:Panel ID="Panel1" runat="server" CssClass="modalpopup" Style="display:none">
    <table class="nav-justified">
    <tr>
    <td class="modal-sm" style="width: 251px">Role Name</td>
    <td>
    <asp:TextBox ID="Text_Role" runat="server"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td class="modal-sm" style="width: 251px">&nbsp;</td>
    <td>
    <asp:CheckBoxList ID="CheckBoxList1" runat="server">
    </asp:CheckBoxList>
    </td>
    </tr>
    <tr>
    <td class="modal-sm" style="width: 251px">&nbsp;</td>
    <td>
    <asp:Button ID="Button1" runat="server" Text="Add Role" />
    <asp:Button ID="Button2" runat="server" Text="Cancel" />
    </td>
    </tr>
    </table>

    </asp:Panel>
    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="AddRole_Linkbtn" PopupControlID="Panel1" CancelControlID="Button2" BackgroundCssClass="modalBackground1"></ajaxToolkit:ModalPopupExtender>

    </asp:Content>

    .CS

    protected void AddRole_Linkbtn_Click(object sender, EventArgs e)
    {
    DataTable dtPrivileges = new DataTable();
    Master_Class obj = new Master_Class();
    dtPrivileges = obj.GetPrivileges();
    if (dtPrivileges != null && dtPrivileges.Rows.Count > 0)
    {
    CheckBoxList1.DataSource = dtPrivileges;
    CheckBoxList1.DataTextField = "Privilege_Name";
    CheckBoxList1.DataBind();

    }
    ModalPopupExtender1.Show();
    }

    Friday, December 21, 2018 7:44 AM

All replies

  • User283571144 posted

    Hi Neethu38,

    My Problem is that the Button Click Event is not triggering when I click it.

    To check,I added another Button and the same problem facing again.

    According to your codes, I found you don't bind OnClick Event for Button1 and Button2 inside the model popup.

    If you don't bind the event for the button, it will not trigger the code-behind event.

    I suggest you could try to add the onclick attribute for the button, then it will work well.

    More details, you could refer to below codes:

    <asp:Panel ID="Panel1" runat="server" CssClass="modalpopup" Style="display:none">
    <table class="nav-justified">
    <tr>
    <td class="modal-sm" style="width: 251px">Role Name</td>
    <td>
    <asp:TextBox ID="Text_Role" runat="server"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td class="modal-sm" style="width: 251px">&nbsp;</td>
    <td>
    <asp:CheckBoxList ID="CheckBoxList1" runat="server">
    </asp:CheckBoxList>
    </td>
    </tr>
    <tr>
    <td class="modal-sm" style="width: 251px">&nbsp;</td>
    <td>
    <asp:Button ID="Button1" runat="server" Text="Add Role" OnClick="Button1_Click"  />
    <asp:Button ID="Button2" runat="server" Text="Cancel" OnClick="Button2_Click"  />
    </td>
    </tr>
    </table>
    
    </asp:Panel>

    Code-behind:

    protected void Button1_Click(object sender, EventArgs e)
            {
    
    Response.Write("fired"); }

    Best Regards,

    Brando

    Monday, December 24, 2018 10:08 AM
  • User1405798523 posted
    Hi, thanks for your reply but i have the onclick code for both button1 and button2. As the importance goes to the link button, i pasted that code part only.
    Monday, December 24, 2018 11:19 AM
  • User283571144 posted

    Hi Neethu38,

    According to your description, I still couldn't understand your issue clearly.

    Do you mean the AddRole linkbutton click event is not work or something else?

    If you could post more details information, it will be more easily for us to reproduce the issue.

    I have created a test demo on my side, it works well.

    Result:

    Best Regards,

    Brando

    Tuesday, December 25, 2018 9:55 AM