tags:

views:

332

answers:

1

I've got an asp.net web form, there is an update panel that contains a table with textboxes that the user enters values into. The table is in an updatepanel as the textboxes are generated from a very long running db query. It is generated a few seconds after the form loads using a timer control.

When the form is posted back the table isn't available to our code...

Here is the code for that section, this is a DynamicData edit page.

 <asp:UpdateProgress ID="UpdateProgress1" runat="server" 
            AssociatedUpdatePanelID="UpdatePanel2">
            <ProgressTemplate>
                <div>Getting subjects...</div>
            </ProgressTemplate>
        </asp:UpdateProgress>
        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"  >
            <ContentTemplate>
                <asp:Timer ID="Timer1" runat="server" Interval="2000" Enabled="false" >
                </asp:Timer>
                <div id="subjects_fav">
                    <asp:Table ID="tabSubjectsFav" runat="server" BorderWidth="2" BorderColor="Aquamarine">
                    </asp:Table>
                </div>

            <asp:Button ID="UpdateButton" runat="server" OnClick="SaveEverything" Text="Save Everything" />

            </ContentTemplate>
        </asp:UpdatePanel>


Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
    'DynamicDataManager1.RegisterControl(DetailsView1)
    DynamicDataManager1.RegisterControl(lvArticles1)
    DynamicDataManager1.RegisterControl(lvArticles2)
    DynamicDataManager1.RegisterControl(lvArticles3)
    DynamicDataManager1.RegisterControl(lvArticles4)
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    'trying to get the id_project for this page
    'get article id for first article

    If Not IsPostBack Then
        Timer1.Enabled = True
    Else
        UpdatePanel2.Update()
    End If

    'now get related project from db
    Dim db As New MTRData.mtddDataContext()
    Dim art = (From a In db.articles _
                 Where a.id = Request.QueryString("id") Take 1 _
                 Select a).SingleOrDefault()
    'txtid_project.Text = art.id_project

    'need to use this all over the place so saving it as a property type thing as well
    _ProjectID = art.id_project
    _PublicationID = art.id_publication
    _ArticleID = art.id

End Sub

Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    If boolTimerFired = False Then
        Timer1.Enabled = False
        boolTimerFired = True
        GenerateSubjectsFavGrid(_ArticleID)
        UpdatePanel2.Update()
    End If
    Timer1.Enabled = False

End Sub
+2  A: 

Can't really diagnose this without some code. I'm guessing that you're generating the textboxes in the wrong part of the page lifecycle though. If you're not doing it during OnInit(), and then rebuilding them in the same way on the submit, then there won't be any textboxes on the form.

Remember that each new postback creates a new page object with a fresh new set of control instances. If your dynamic controls aren't created the same way each time, then they just won't be there.

womp
Hi womp, thanks for that, the're not being done in OnInit because they take 30 seconds to pull the current values out of the db (don't ask!). So they are done a couple of seconds after the page loads via a timer...
DaveEHS
Yeah, if "GenerateSubjectsFavGrid(_ArticleID)" is where you're adding your textboxes dynamically to the page, then this is the problem. Any controls added here will simply not be there in the next Page object created on the next postback. Is the grid always the same size? Any chance of making the grid non-dynamic, setting visibility to false, and just showing it when it's done populating?
womp
Hi womp, sadly not, will vary from client to client. Won't the values be in response.form? I guess I will have to save the values to the session or something when they change via JavaScript and then populate the values from there. Actually having this conversation makes me think that I could probably cache the controls required somehow and then just worry about the values going into the session or something. Thanks for I advertedly pointing me in the right direction. Cheers, Dave.
DaveEHS
The actual values will be in response.form... but the textboxes won't be appearing in the new Page object, so they won't go anywhere. If you can regenerate your textboxes the exact same way so that they have the same ID's and whatnot, then retrieving them from there is one way to do it. Kind of like implementing your own viewstate. Note that for list controls, this wouldn't work, because only the selected value comes through in the form post... not the rest of the list, so your lists would need rebinding. But only one value is associated with textboxes, so it could work.
womp
Brilliant, thanks again.
DaveEHS
Update: Got the values out of the response.form to update the database and then just enabled the timer that updated the grid in the update panel to display it again.
DaveEHS

related questions