locked
Problem with TextBox+LinkButton+GridView inside UpdatePanel RRS feed

  • Question

  • User-2044969471 posted

    In theory I understand what's going on but I can't find any working solution. I'm not very experienced ASP.NET developer.

    I have a FormView which contains some field in EditTemplate. I want to use UpdatePanel and PopupControlExtender to show a grid to lookup values from.

    There are many records to select from so I want to allow user to filter grid before making selection. I've placed "FilterByTextBox" and link button to filter records inside gridview. Pretty standard design patterm as I thought.

    The problem is "FilterByTextBox" is always empty in linkbutton's OnClick event. I can't get it's value. How and where I can store textbox's value to access it later in OnClick event?

    FilterByTextBox, linkbutton and GridView are inside UpdatePanel. Whole page is inside master page.

    Maybe there is any good example which uses my pattern?

    Thursday, February 20, 2014 4:36 AM

Answers

  • User-417640953 posted

    Hi AlexeiPavlov,

    Thank you post the issue to asp.net forum.

    According to your description, I see that you want to get the "FilterByTextBox" text when LinkButton clicked.

    Then based on the text to filter data and bind the filtered data to gridview. Popup show the gridview in the client.

    For this issue, I made a simple demo below, please check it.

     <div>
            <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:TextBox ID="FilterByTextBox" runat="server"></asp:TextBox>
                    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Click Me</asp:LinkButton>
                    <asp:HiddenField ID="HiddenField1" runat="server" />
                    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" 
                         TargetControlID ="HiddenField1" PopupControlID="Panel1"
                         OkControlID="Button1" CancelControlID="Button2"> 
                    </asp:ModalPopupExtender>
                    <asp:Panel ID="Panel1" runat="server" style="display:none">
                        <asp:GridView ID="GridView1" runat="server"  > </asp:GridView>
                        <asp:Button ID="Button1" runat="server" Text="OK" />
                        <asp:Button ID="Button2" runat="server" Text="Cancel" />
                    </asp:Panel>
                </ContentTemplate>
            </asp:UpdatePanel>
      </div>

    code behind:

      public DataTable testTable=null;
            protected void Page_Load(object sender, EventArgs e)
            {       //test data
                    testTable = new DataTable();
                    testTable.Columns.Add("ID");
                    testTable.Columns.Add("Name");
                    testTable.Rows.Add(1,"jhon1");
                    testTable.Rows.Add(2, "jhon2");
                    testTable.Rows.Add(3, "jhon3");
                    testTable.Rows.Add(4, "jhon4");
                    testTable.Rows.Add(5, "jhon5");
                    testTable.Rows.Add(6, "jhon6");  
            }
    
            protected void LinkButton1_Click(object sender, EventArgs e)
            {
                int filterID =Convert.ToInt16( this.FilterByTextBox.Text);
                DataView dv = testTable.DefaultView;
                dv.RowFilter = "ID>" + filterID;
                this.GridView1.DataSource = dv;
                this.GridView1.DataBind();
                this.ModalPopupExtender1.Show();
            }

    Hope this helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 25, 2014 1:35 AM

All replies

  • User-417640953 posted

    Hi AlexeiPavlov,

    Thank you post the issue to asp.net forum.

    According to your description, I see that you want to get the "FilterByTextBox" text when LinkButton clicked.

    Then based on the text to filter data and bind the filtered data to gridview. Popup show the gridview in the client.

    For this issue, I made a simple demo below, please check it.

     <div>
            <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:TextBox ID="FilterByTextBox" runat="server"></asp:TextBox>
                    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Click Me</asp:LinkButton>
                    <asp:HiddenField ID="HiddenField1" runat="server" />
                    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" 
                         TargetControlID ="HiddenField1" PopupControlID="Panel1"
                         OkControlID="Button1" CancelControlID="Button2"> 
                    </asp:ModalPopupExtender>
                    <asp:Panel ID="Panel1" runat="server" style="display:none">
                        <asp:GridView ID="GridView1" runat="server"  > </asp:GridView>
                        <asp:Button ID="Button1" runat="server" Text="OK" />
                        <asp:Button ID="Button2" runat="server" Text="Cancel" />
                    </asp:Panel>
                </ContentTemplate>
            </asp:UpdatePanel>
      </div>

    code behind:

      public DataTable testTable=null;
            protected void Page_Load(object sender, EventArgs e)
            {       //test data
                    testTable = new DataTable();
                    testTable.Columns.Add("ID");
                    testTable.Columns.Add("Name");
                    testTable.Rows.Add(1,"jhon1");
                    testTable.Rows.Add(2, "jhon2");
                    testTable.Rows.Add(3, "jhon3");
                    testTable.Rows.Add(4, "jhon4");
                    testTable.Rows.Add(5, "jhon5");
                    testTable.Rows.Add(6, "jhon6");  
            }
    
            protected void LinkButton1_Click(object sender, EventArgs e)
            {
                int filterID =Convert.ToInt16( this.FilterByTextBox.Text);
                DataView dv = testTable.DefaultView;
                dv.RowFilter = "ID>" + filterID;
                this.GridView1.DataSource = dv;
                this.GridView1.DataBind();
                this.ModalPopupExtender1.Show();
            }

    Hope this helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 25, 2014 1:35 AM