0

I have the following table in an ascx user controll:

<tr runat="server" id="rowChangeSerNo">
        <td colspan="2">
            <table id="tblChangeSerNo" runat="server">
            </table>
        </td>
</tr>
<tr id="row" runat="server">
    <td>
        <asp:Button ID="btChangeSerNo" runat="server" Text="Update" OnClick="btChangeSerNo_onClick" />
    </td>
 </tr>

I create the tblChangeSerNo dynamically with text boxes prefilled with the current values in the db. The idea of the control is to allow the user to update the values of the DB with new values. The problem is that when the btChangeSerNo_onClick method is called:

  • The table is not rendered, since I do it on pre-render
  • Even if I rendered the table on Page_Load I could not access updated values of the user because they are lost.

How can I solve this problem?

1
  • Can you show us the code-behind? Commented May 17, 2011 at 10:54

1 Answer 1

1

The best practice way will be to use Grid control instead.

If you prefer to stick with your own code, follow those steps:

  1. Store all the text boxes in global fields, e.g. public List<TextBox> m_tableTextboxes = new List<TextBox>(); and when creating add to that list.
  2. Have the code creating the dynamic controls in the Page_Load but execute it only when not is PostBack: if (!Page.IsPostBack) { ... }
  3. In the button click event, read the values from your global field.

Done something similar in the past, so the concept should work.

Sign up to request clarification or add additional context in comments.

2 Comments

The problem is that the code is in an ascx control, so that the public List<TextBox> m_tableTextboxes = new List<TextBox>(); line is executed every single time even accross postbacks:(
@woola this should not matter.. as far as I remember once the controls were added to the page they should stay there on post back unless explicitly overwritten. I might be wrong, but it surely worth a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.