views:

269

answers:

3

I have a asp.net control that represents a table and a control that represents a row in the table. Each row contains a text field for a date and a button to submit the date entered.

<asp:TextBox ID="TextBox" runat="server"/>
<asp:ImageButton ID="SubmitButton" onclick="SubmitButton_Click" runat="server" />

The button fires an event which triggers an update in the database.

protected void SubmitButton_Click(object sender, EventArgs e)
{
    //Validate information in TextBox
    //Submit to database
}

This should cause a new set of rows to be shown based on the information entered in the text box. However, the updated information is not being shown unless I force a page refresh. I suspect this is because of where event handling falls in the asp.net page/control lifecycle. As near as I can tell the values are loaded into the rows before the event is actually triggered, which causes them to get the old values and not the new values that they should have.

My question is what is the best way to get around this? I'm assuming it will be something like checking to see if it's a postback in the page load event and not loading the user control rows but instead causing them to load or to refresh from the event somehow but I'm not sure what that should look like.

Edit: I think I need to call the same function that is being called in the Page_Load but I'm not sure how to get to it from the custom control I guess.

+3  A: 

I think you need to re-bind your grid after your event has fired.

Locksfree
I'm not using a Gridview for reasons that are too lengthy to describe here.
@mwright Re-bind your "custom created and dynamically loaded" controls.
mxmissile
+1  A: 

As Locksfree said, a rebind is what you are probably looking for.

Postback does not automatically show new data unless you specifically request the new data by calling DataBind() of your asp.net object.

If you are dynamically creating the table then you will have to rerun the code to rebuild your table again to get the new data. Depending on how it is built you may be able to get away with a partial reload of just the new data.

Eddie