radiobuttonlist postback error

Thread Solved

Join Date: Jul 2009
Posts: 7
Reputation: phantom1000000 is an unknown quantity at this point 
Solved Threads: 0
phantom1000000 phantom1000000 is offline Offline
Newbie Poster

radiobuttonlist postback error

 
0
  #1
Oct 30th, 2009
Hi all,
I've got a spot of bother with my radiobuttonlist. It has 3 items in it and I want them to control the visibility of certain divs/tables.

But even simple text changes are becoming a headache and the postback is not firing the event I clicked on but the PREVIOUS event (ie, I click on value 1 and text shows nothing, I click on value 2 and text shows value 1, I click on value 3 and text shows value 2)...always 1 step behind.

Here's my code:
  1. function SetMessageInTextbox() {
  2. var rdolist_0 = document.getElementById("rdolist_0");
  3. var rdolist_1 = document.getElementById("rdolist_1");
  4. var rdolist_2 = document.getElementById("rdolist_2");
  5. if (rdolist_0.checked)
  6. document.getElementById("TextBox1").value="One";
  7. if (rdolist_1.checked)
  8. document.getElementById("TextBox1").value="Two";
  9. if (rdolist_2.checked)
  10. document.getElementById("TextBox1").value="Three";
  11. }

I've tried combinations of adding attributes in the vb.net pageload function, the vb.net code behind rdoList.selectindexchange using
rdolist.Attributes.Add("onload", "javascriptetMessageInTextbox()")
and also the onClick event of the HTML page.

If you can assist, please do.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 225
Reputation: mail2saion is an unknown quantity at this point 
Solved Threads: 34
mail2saion's Avatar
mail2saion mail2saion is offline Offline
Posting Whiz in Training
 
1
  #2
Nov 1st, 2009
HI,
You can use the below javascript method to read asp radio button list selectindex, selected value.
  1. <script type="text/javascript">
  2.  
  3. function GetRadioButtonSelectedValue()
  4. {
  5. var AspRadio = document.getElementsByName('Aspradiobuttonlist');
  6.  
  7. for (var i = 0; i < AspRadio.length; i++)
  8. {
  9.  
  10. if (AspRadio[i].checked)
  11. {
  12. var lblAspradiobuttonValue = document.getElementById('<%= lblAspradiobuttonValue.ClientID %>');
  13.  
  14. lblAspradiobuttonValue.innerHTML='<b>Selected Value:</b> '+AspRadio[i].value+'<br/>';
  15. lblAspradiobuttonValue.innerHTML+='<b>Selected Text:</b> '+AspRadio[i].parentNode.getElementsByTagName('label')[0].innerHTML;
  16. }//end if
  17.  
  18. }// end for
  19.  
  20. }//end function
  21. </script>

WHERE Aspradiobuttonlist is the id of radiobuttonlist server control.

Hope it will help you.
Last edited by mail2saion; Nov 1st, 2009 at 5:35 am.
MARK AS SOLVED if its help you.

REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 7
Reputation: phantom1000000 is an unknown quantity at this point 
Solved Threads: 0
phantom1000000 phantom1000000 is offline Offline
Newbie Poster
 
0
  #3
Nov 3rd, 2009
Hi,

Thanks for the reply. Unfortunately, you're code doesn't have the desired result. What does seem to happen is that if I make a selection, no answer will appear, but if I next press the area around a radiobutton, but still on the radiobuttonlist control, it will respond with the correct response.

So in other words, the change of index doesn't fire the function, but clicking the list (not a direct radiobutton) does.

This is counter-intuitive if you ask me and I can't expect the users of the page to do this.

Any clues?

Thanks again.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 7
Reputation: phantom1000000 is an unknown quantity at this point 
Solved Threads: 0
phantom1000000 phantom1000000 is offline Offline
Newbie Poster
 
0
  #4
Nov 3rd, 2009
Okay, just figured it out. Now I think about it, it makes a bit of sense. I forgot javascript gets loaded with the page and therefore it does not need to post back to the server. I had autopostback set to true and by setting this to false, the desired effect came into play.

Thank you for your help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum


Views: 411 | Replies: 3
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC