I have an ASP.NET AJAX page on my site that dynamically creates a moderate number (up to 56) of radio buttons presented in a table, each of which allows the user to select a specific item.
Data associated with each radio button is encoded in the button's ID. Processing a radio button click is done in the page's Page_Load event handler, by checking the ScriptManager's AsyncPostBackSourceElementID.
This approach is not great, but it seems relatively lightweight and works!
However, I need my page to work when JavaScript is turned off in the browser.
Step 1 - in this scenario replace the radio buttons with buttons so that we will get a postback to the server when they are clicked
Step 2 - get the button ID. This no longer works, since JavaScript is turned off.
So, the question is: How do I determine the ID of the control that caused the postback?
Check Request["__EVENTTARGET"]. That should contain the client ID of the button that triggered the postback. It should also work to find the ID of a radio button that raised a postback via AutoPostBack's onclick.
richardnever...
Member
81 Points
31 Posts
Determining postback control ID when JavaScript is disabled
Aug 26, 2008 04:01 PM|LINK
I have an ASP.NET AJAX page on my site that dynamically creates a moderate number (up to 56) of radio buttons presented in a table, each of which allows the user to select a specific item.
Data associated with each radio button is encoded in the button's ID. Processing a radio button click is done in the page's Page_Load event handler, by checking the ScriptManager's AsyncPostBackSourceElementID.
This approach is not great, but it seems relatively lightweight and works!
However, I need my page to work when JavaScript is turned off in the browser.
Step 1 - in this scenario replace the radio buttons with buttons so that we will get a postback to the server when they are clicked
Step 2 - get the button ID. This no longer works, since JavaScript is turned off.
So, the question is: How do I determine the ID of the control that caused the postback?
Comments on the approach used are also welcome.
dwhite
Star
8990 Points
1423 Posts
Re: Determining postback control ID when JavaScript is disabled
Aug 26, 2008 05:21 PM|LINK
Have a look here: http://geekswithblogs.net/mahesh/archive/2006/06/27/83264.aspx
Hope this helps,
-Damien
Latest Blog Post: BDD with ASP.NET MVC and Cucumber
gt1329a
All-Star
15377 Points
2501 Posts
ASPInsiders
MVP
Re: Determining postback control ID when JavaScript is disabled
Aug 26, 2008 05:24 PM|LINK
A guide to combining jQuery and ASP.NET: jQuery for the ASP.NET developer
richardnever...
Member
81 Points
31 Posts
Re: Determining postback control ID when JavaScript is disabled
Aug 27, 2008 08:14 AM|LINK
Thanks for the two responses there - however the key thing here is that this has to work with JavaScript disabled.
The __EVENTTARGET form value only gets set if JavaScript is enabled...