CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    One control updating another.

    I have a very simple question.

    An ASP Web form with 3 controls. Label, ComboBox and Button. When the page loads the Label and ComboBox both contain the same text. This bit works ok.

    I choose a new item from the ComboBox drop down and press the button. Which does a postback (as there is some server side stuff that needs to be done).

    How can I get the Label to display the newly selected ComboBox item?

    It seems as though my server code, reacting to the Button.OnClick() event, is executed AFTER the page (Label) is reloaded, so it does not get the new value until the next time around...

    What is the correct way to do this? I'm getting a bit frustrated
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: One control updating another.

    You are correct that event handling comes after the PageLoad, so what you should (can) do is to wrap the loading code which initialize the label inside a check that the page is not a postback (there is a method on the Page object for this), so it only gets sets the first time the page loads.

    Then in the buttons event handler, you'll set the new value for the label.

  3. #3
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: One control updating another.

    Alsvha,

    Thank you for confirming what I just ended up doing to get it working! I just didn't think it was the correct way, but it seems to work smoothly and the database accesses (in the background) only happen when required...
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

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

Featured