Radio Button Hell

D

Dominic Godin

Hi,

I have a some radio buttons on a aspx page that cause a post back. I
need to get the checked status in the page_init event handler. However
it seems that the checked status is only updated after the page_init
event. Any way I can get arround this?

I'll give a quick example in C#. These two methods are fired when I
check the radio button radioBtnExample

void Page_Init(Object sender, EventArgs e)
{
// false here
bool buttonState = radioBtnExample.Checked;

SetUpDataGridColumns(buttonState);
}

private void radioBtnExample_CheckedChanged(object sender,
System.EventArgs e)
{
// true here
bool buttonState = radioBtnExample.Checked;

BindDataToDataGrid(buttonState);
}

Any help would be most welcome

Dominic Godin
 
J

jagadeesh

Hi,
the values will be filled in only after Init event. So you can access the
values only after init. You can put the same code in page load to get the
values.
Hope this may solve.
Jagadeesh
 
D

Dominic Godin

Hi,

Dosn't help. The SetUpDataGridColumns(buttonState) must be run in the
init to work properly. Any body else no a way round this?

Dominic Godin
 
K

Kevin Spencer

The problem is that you're starting off with the wrong assumption ("I need
to get the checked status in the page_init event handler"). You DON'T need
to get the checked status in the page_init event handler. You DO need to
fulfill the requirements of your application, which doesn't dictate HOW you
fulfill those requirements. The architecture of ASP.Net dictates how you
fulfill those requirements. Here is a link to an outline of the
System.Web.UI.Control Execution Lifecycle. If you work with it as intended,
you should have no problem:

http://msdn.microsoft.com/library/d...guide/html/cpconControlExecutionLifecycle.asp

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
D

Dominic Godin

Hi,

Interesting article thanks. I will have to think a little more when
designing pages after reading that.

Got it working. Seems that I have to reload the page twice to get data
into the init.

The page loads once on the postback, gets to the event where I set a
session var and reload the page. The init then checks for this session
var.

Dominic Godin
 
W

William F. Robertson, Jr.

You can do a Request.Form["id"] and get the values. I think the Request is
loaded by Init. This really isn't asp.net functionality, but it will get
your desired result.

What are you doing that you can't do this from Page_Load?

bill
 
D

Dominic Godin

I have a data grid that shows a data table. There are some radio buttons
that will change the data table displayed. When they click the radio
button I build the boundColumns and add them to the datagrid. This can
only be done in the init for the columns to work properly.

I have it working now. Just had to take a different approach.

Dominic Godin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top