Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a page with a set of radio buttons. The radio buttons are in an update panel and each has AutoPostBack set to true. They all share a common CheckedChanged event handler in the code-behind page. There are certain conditions during page load when I want a particular radio button to be set to true. When I do this in code during the page load event, the radio buttons will not respond to the CheckedChanged event unless I do something else to cause the page to post back. Anyone know what's causing this?
Posted

I don't understand. "On the server side when your code changes the state of any controls, the result will not be yet another postback." I do not expect another postback from the changes made on the server side. I am handling that in code. But once the page finishes loading, and the server-side script is complete, I expect client-side events to happen. The radio buttons should postback when their state is changed. That is not happening until some other control causes a postback. Then the radio buttons work normally.
 
Share this answer
 
Comments
[no name] 12-Oct-11 10:04am    
Sorry, but that's not the way it works. Postbacks are triggered when you use a control on the client side, that's it.

On the server side, in your code, you are responsible to make all changes to the page's state yourself. No event will be triggered, not even when the client has received the rsponse. As I see it, this is very wise. What would you think of a page that immediately reloads just after finishing reloading? And, in the worst case, every postback would again trigger more postbacks. A page trapped in an endless sequence of postbacks would also not be really great.
Lonnie Raffray 12-Oct-11 10:10am    
Maybe I'm wording it wrong. I am NOT trying to trigger the event in code. I want to set one of the radio buttons in code WITHOUT triggering it's CheckedChanged event. Once the page is finished loading, it needs to respond to client-side events as a normal radio button should, but it is NOT. If I comment out the server-side code, it works fine.
[no name] 12-Oct-11 10:22am    
Ok, got it. That's another consequence of the page's lifecycle. Each control goes through a similar lifecycle as the page itself, but you can't always expect it to be in step with the page. Perhaps you are simply too early. Try moving that part into the PreRender method. At that point all controls should have their states sorted out and you can make last second changes to those states. Also, you can try unchecking the other radio buttons as well, I suspect that the needed second postback before they work again is just because of that.
Lonnie Raffray 12-Oct-11 10:28am    
Thanks! Moving the code to the PreRender handler did the trick.
[no name] 12-Oct-11 17:21pm    
Great. Next time something like this happens it will not hold you up so long.
Yes, the cause is probably that you don't understand the lifecycle of ASP .Net pages very well.

Postbacks are requests that are triggered by little snippets of JavaScript embedded in the HTML on the client side. On the server side when your code changes the state of any controls, the result will not be yet another postback. Whatever you want to happen, you will have to see to it yourself by adding methods which do what you want to happen. You can then call those methods from the event handler and also when you make any changes which will not trigger another postback.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900