|
-
June 8th, 2008, 09:37 PM
#1
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.......
-
June 8th, 2008, 11:25 PM
#2
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.
-
June 8th, 2008, 11:49 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|