Question

I have two radio button on my asp.net page, with AutoPostBack = True
When I click on either of those, they each set a flag SaveData=False

However, when I click on them, the page_load event occurs first, so the page_load event saves the data, then the radiobutton_OnCheckedChanged event is triggered.

How can I trigger the OnCheckedChanged before the page_load event?

Was it helpful?

Solution

You can't trigger the OnCheckedChanged before radiobutton_OnCheckedChanged because that's the normal page life cycle.

You can check in Page_Load if Page.IsPostBack is true or not, and then don't save (or save) the data.

OTHER TIPS

You can't.

You need to read up on the page lifecycle.

Troy - you will have to take care of this on the client side (javascript / jquery). Your AutoPostBack = True causes the form to do a postback which calls page load. Its all about how the page lifecycle and server side events work.

You can't the page always needs to load before events can be fired. This has to do with control creation, view state management, control state, etc.

What you want to do in your Page_Load is something like:

if(!this.IsPostBack) 
{
   // Do the stuff you want on the initial page load
}

Anything that you do not want to happen when the radio buttons are clicked, put it inside the if {} block. IsPostBack indicates that the page is processing a post-back event, which is what happens when you click one of your radio buttons.

You can't change the order/sequence of event handler execution. However you may move the code inside the page_load to another event handler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top