+ Reply to Thread
Results 1 to 2 of 2

Thread: Dynamic Control doesn't update on first postback

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Dynamic Control doesn't update on first postback

    I have some code that generates dynamic controls depending on the type of control I want to show. At the moment I just have a date type that displays a text box and a calendar control that are created dynamically.

    The controls are built inside a repeater, as there may be more than 1 on the page, which inturn is inside an accordion control. And then I have an Image button control inside the accordion which is clicked to update the database.

    Code:
    <accordion>
        <repeater>
            <controls />
        </repeater>
        <imagebutton />
    </accordion>
    
    I have the code that generates the controls in the Page_Load event outside of "if not ispostback....end if" section ie it fires on every Page_Load.

    All of this seems to be working fine. The textbox and calendar controls appear each time the page is loaded.

    The problem is if, for example, one of the date textboxes is empty and you type a date into it, when you click the update button when the page first loads, it doesn't save the data. If when the page reloads you enter the date and click the button, it does save it.

    I can't work out why the data is not saved on the 1st button click but is on the 2nd one. I presume it's something to do with the page having been posted back once already, but I can't think what is being done differently on the postback compared to when the page first loads.

    Does anyone know why this would happen?

    I hope all of that makes sense. Let me know if you need more info.

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    OK. I think I found the answer.

    Needed to create the controls in the Page_Init event, not Page_Load.

+ Reply to Thread

Similar Threads

  1. Replies: 5
    Last Post: April 23rd, 2010, 07:14 PM
  2. Object Reference Error on Custom Control Postback
    By richyrich in forum .NET Development
    Replies: 1
    Last Post: September 22nd, 2008, 06:56 PM
  3. Retrieving DataItem on Postback
    By richyrich in forum .NET Development
    Replies: 4
    Last Post: July 21st, 2008, 11:15 AM
  4. Update Panel
    By Shem in forum .NET Development
    Replies: 3
    Last Post: July 10th, 2008, 05:37 AM
  5. Finding Datalist Row on auto postback
    By richyrich in forum .NET Development
    Replies: 1
    Last Post: May 12th, 2008, 05:52 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO