locked
Linkbutton not firing within updatepanel RRS feed

  • Question

  • User-1901014284 posted

    Hi,

    I am having an issue of LinkButton's not firing within an update panel and content template, I do not receive an error message on the button click. When I remove the update panel and content template the button's work with no issue at all. I only require the update panel and content template as I am working with a tab panel and would like to stay on the same tab when a postback event is fired using my dropdown menus.

    <div role="tabpanel" class="tab-pane" id="ArchiveRAs">
    
           <asp:UpdatePanel ID="updatePanel2" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
    
       <table style="width:20%; float: left;">
    
      <tr>
        <th>Search Documents</th>
      </tr>
      <tr>
        <td>            
                <asp:TextBox ID="txtSearchArchive" runat="server" OnTextChanged="txtSearchArchive_TextChanged" Height="30px" Width="380px"></asp:TextBox>
                <asp:Button ID="SearchbtnArchive" runat="server" Text="Search" style="left: 0px; top: 0px; width: 150px; height: 60px; background-color: #DF554C; font-weight: bold; font-size: medium;" BackColor="White" />
                </td>
        </table>       
             
            <table style="width:20%; float: left;">
      <tr>
    
        <th>Search by Department</th> 
      </tr>
      <tr>
        <td> 
                <asp:DropDownList ID="SelectArchiveDeptddl" runat="server" Height="45px" Width="380px" CssClass="auto-style9" AutoPostBack="true" onselectedindexchanged="SelectArchiveDeptddl_SelectedIndexChanged" Font-Names="Arial" Font-Size="Medium" causesvalidation="false">
                    </asp:DropDownList>
                    </td> 
                </tr>
            </table>
    
    
            <table style="width:20%; float: left;">
      <tr>
    
        <th>Search by Risk Assessment</th> 
      </tr>
      <tr>
        <td> 
                <asp:DropDownList ID="SelectArchiveRAddl" runat="server" Height="45px" Width="380px" CssClass="auto-style9" AutoPostBack="true" onselectedindexchanged="SelectArchiveRAddl_SelectedIndexChanged" Font-Names="Arial" Font-Size="Medium" causesvalidation="false">
                    </asp:DropDownList>
                    </td> 
                </tr>
            </table>
    
            <br />
            <br />
    
    
    
            <asp:GridView ID="ArchiveGridView" runat="server" CssClass="mydatagrid" PagerStyle-CssClass="pager" HeaderStyle-CssClass="header" RowStyle-CssClass="rows" AllowPaging="True" OnItemDataBound="Item_Bound" >
            <Columns>  
            <asp:TemplateField ItemStyle-HorizontalAlign="Center">  
                <ItemTemplate>  
                    <asp:LinkButton ID="lnkDownload" runat="server" OnClick="DownloadArchiveFile" class="fa fa-download" CommandArgument='<%# Eval("Id") %>'></asp:LinkButton>  
                    <asp:LinkButton runat="server" ID="link" CommandArgument='<%# Eval("id") %>' OnClick="link_Click_Archive" CssClass="fa fa-edit"></asp:LinkButton>
                </ItemTemplate>  
            </asp:TemplateField>  
        </Columns>  
    </asp:GridView>
    
        </ContentTemplate>
    </asp:UpdatePanel>
    
            
    </div>

    Thanks in advance for any assistance, it is greatly appreciated.

    Kind regards

    Jonny Lewis

    Wednesday, November 4, 2020 12:58 PM

Answers

  • User-939850651 posted

    Hi jonnygareth30,

    According to your description, I created a simple example to reproduce your problem. You could try to loop though the rows in the GridView and register these LinkButtons as PostBack.

    Please refer to code below:

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack) {
                    bindGrid();
                }
            }
    
            private void bindGrid() {
                DataTable dt = new DataTable();
                string conStr = ConfigurationManager.ConnectionStrings["conStr"].ToString();
                using (SqlConnection conn = new SqlConnection(conStr)) {
                    string query = "select * from tbl_default";
                    using (SqlCommand cmd = new SqlCommand(query, conn)) {
                        SqlDataAdapter sda = new SqlDataAdapter(cmd);
                        sda.Fill(dt);
                        ArchiveGridView.DataSource = dt;
                        ArchiveGridView.DataBind();
                    }
                }
                RegisterPostBackControl();
            }
    
            private void RegisterPostBackControl()
            {
                foreach (GridViewRow row in ArchiveGridView.Rows)
                {
                    LinkButton btnFull = row.FindControl("lnkDownload") as LinkButton;
                    ScriptManager.GetCurrent(this).RegisterPostBackControl(btnFull);
                }
            }
    
            protected void txtSearchArchive_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            protected void SelectArchiveDeptddl_SelectedIndexChanged(object sender, EventArgs e)
            {
    
            }
    
            protected void SelectArchiveRAddl_SelectedIndexChanged(object sender, EventArgs e)
            {
    
            }
    
            protected void DownloadArchiveFile(object sender, EventArgs e)
            {
                LinkButton btn = (LinkButton)sender;
                Response.Write(btn.UniqueID);
                RegisterPostBackControl();
            }
    
            protected void link_Click_Archive(object sender, EventArgs e)
            {
    
            }

    Result:

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 5, 2020 5:16 AM

All replies

  • User-939850651 posted

    Hi jonnygareth30,

    According to your description, I created a simple example to reproduce your problem. You could try to loop though the rows in the GridView and register these LinkButtons as PostBack.

    Please refer to code below:

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack) {
                    bindGrid();
                }
            }
    
            private void bindGrid() {
                DataTable dt = new DataTable();
                string conStr = ConfigurationManager.ConnectionStrings["conStr"].ToString();
                using (SqlConnection conn = new SqlConnection(conStr)) {
                    string query = "select * from tbl_default";
                    using (SqlCommand cmd = new SqlCommand(query, conn)) {
                        SqlDataAdapter sda = new SqlDataAdapter(cmd);
                        sda.Fill(dt);
                        ArchiveGridView.DataSource = dt;
                        ArchiveGridView.DataBind();
                    }
                }
                RegisterPostBackControl();
            }
    
            private void RegisterPostBackControl()
            {
                foreach (GridViewRow row in ArchiveGridView.Rows)
                {
                    LinkButton btnFull = row.FindControl("lnkDownload") as LinkButton;
                    ScriptManager.GetCurrent(this).RegisterPostBackControl(btnFull);
                }
            }
    
            protected void txtSearchArchive_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            protected void SelectArchiveDeptddl_SelectedIndexChanged(object sender, EventArgs e)
            {
    
            }
    
            protected void SelectArchiveRAddl_SelectedIndexChanged(object sender, EventArgs e)
            {
    
            }
    
            protected void DownloadArchiveFile(object sender, EventArgs e)
            {
                LinkButton btn = (LinkButton)sender;
                Response.Write(btn.UniqueID);
                RegisterPostBackControl();
            }
    
            protected void link_Click_Archive(object sender, EventArgs e)
            {
    
            }

    Result:

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 5, 2020 5:16 AM
  • User-2108448128 posted

    On the linkbutton add onclick="code to be run"

    About the update panel just add at your onclick code at the end (UpdatePanel1.Update();

    Thursday, November 5, 2020 8:38 AM
  • User-1901014284 posted

    Thank you very much, This has worked great and I have also applied to my popup modal which opens with no problems also. The only issue is when opening a popup modal within the updatepanel now this does not keep the active tab open, it resets to the first tab in the tabpanel. is there something different that I would need to do for the popup modal? or add something to the popup modal to choose which panel i would like to keep open for the popup modal?

    Many thanks for all your help.

    Jonny

    Thursday, November 5, 2020 10:32 AM