Results 1 to 4 of 4

Thread: Help - When does data post - newbie

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Help - When does data post - newbie

    Ok, have been doing win app programming for years, but I'm new to web programming. I'm confused on when data gets posted. I have a form with some user data that a load from a SQL Table, and I want to be able to change it and resave it. So I have, for example, a txtUsername text box, and a Submit button with a SQL Update command. I change the text of the txtUserName, and I hit submit....but when i try to load the new data into a command parameter, it still has the old data in it (for example: My name is Sean, I change it to Shaun, but in the code of my Submit button click txtUsername.Text still shows Sean). When does the data get changed? Do I have to enable AutoPostBack on my controls? Thanks.
    Last edited by SeanGrebey; Dec 3rd, 2004 at 03:51 PM.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  2. #2
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251

    Re: Help - When does data post - newbie

    The problem is with the page postback, but not in the way you are thinking.

    See the Page_Load event happens before your button click event. Since when the button click event is triggered it has to make a postback to the server. This causes the Page_Load event to fire again, resetting the change you just made.

    To fix this use the Page.IsPostBack method to figure out if the page has been posted.

    Example:

    Code:
    If Not Page.IsPostBack Then
      'Your stuff to set the textbox
    End If
    Using this will bypass the textbox getting reset before the button click event is fired.
    ~Ryan





    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Help - When does data post - newbie

    yeah, that's it....thanks alot.....
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Help - When does data post - newbie

    Although not a help post, I just wanted to comment on how I've taken the modes of working of web apps and win apps for granted. While the difference in working was always known, it wasn't apparent to me that they were so different. It's always "come naturally" when writing the code. I've seen a few threads like these which make me realize that the concept is entirely different. I'm not sure I went through that phase though.

    <violin plays in background>

Posting Permissions

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



Click Here to Expand Forum to Full Width