Learn how to a build a cloud-first strategyRegister Now


<asp:RadioButtonList and onlick event

Posted on 2007-07-23
Medium Priority
Last Modified: 2011-10-03

I have the following asp:

<asp:RadioButtonList  ID="PorRadioClass" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ToggleClassification" >
                                               <asp:ListItem Text="" Value="Existing"  ></asp:ListItem>
                                                    <asp:ListItem Text="" Value="New"></asp:ListItem>

I want to call a javascript function toggleOn when i click the existing radio and call javascript function toggleoff when i click the New radio. How can i do this?
Question by:Peewee
  • 3
  • 2
LVL 12

Expert Comment

ID: 19548680
can you post back to a single subroutine that uses PorRadioClass.selectedItem.Value to call the appropriate function?

Expert Comment

ID: 19556172
I live in code behind, so I will show you how there.  If ToggleOn/ToggleOff is not used by other controls, this works well.  However, if you are wanting to keep it in the page (not code behind), this isnt as helpful.

Dim strScriptViewSite As String

Select Case PorRadioClass.SelectedValue
  Case is = "Existing"
       strScriptViewSite = "<script>"
       strScriptViewSite += (what ever script ToggleOn does)
       strScriptViewSite += "</script>"
  Case is = "New"
       strScriptViewSite = "<script>"
       strScriptViewSite += (what ever script ToggleOff does)
       strScriptViewSite += "</script>"      
  Case Else
       strScriptViewSite = "<script>alert('You did not choose New or Existing.');</script>"
End Select

ClientScript.RegisterClientScriptBlock(Me.GetType, "ToggleScript", strScriptViewSite)

end if


Author Comment

ID: 19557646
I have created my javascript  in the ascx file. How do i associate script functions to my control PorRadioClass?
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Expert Comment

ID: 19557840
ok.. here is the Javascript version:

<script language="javascript">
        function ToggleClassification() {
            var value1 = window.event.srcElement.value                        
                  if (value1 == "New")
                  if (value1 == "Existing")
        function toggleOn() {
            alert('Toggle On has been activated');
        function toggleOff(){
            alert('Toggle Off has been activated');

Then your control will just call the ToggleClassification sub on the onClick event.  Depending on which IDE you are using, it will probably have an indicator that onClick is not part of that control's "workings", but it will be rendered ok, and therefore can be used.

Now, also... as far as I know (and I dont know javascript as well as others), you might need the control and the javascript on the same page.  Maybe not if it renders ok though.

Let me know if this is what you are looking for!

Author Comment

ID: 19564152
I am using visual studio and i don't seem to have the onclick event available for <asp:RadioButtonList   or for <asp:ListItem. So i can't connect up the function to my control..

Accepted Solution

ggable313 earned 200 total points
ID: 19564920
I know that onClick is not in the list, but it works.  I did it in Visual Studio and that is why I mentioned that it might appear that you cant do it.  You may have a squiggly line, but run the program anyway and you will see that it will render just fine.  The squiggly line shouldnt be red, but green, indicating that it isnt an error, but another type of message.  You will use the onClick for the radiolist itself, not the listitems.

Basically what is happening is that the onClick event is what will work for when the control is rendered HTML since that will be an event that is recognized at that point.

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question