Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

<asp:RadioButtonList and onlick event

Posted on 2007-07-23
6
Medium Priority
?
3,606 Views
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>
                                                </asp:RadioButtonList>

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?
                                             
0
Comment
Question by:Peewee
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

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

Expert Comment

by:ggable313
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

0
 
LVL 5

Author Comment

by:Peewee
ID: 19557646
ggable313,
I have created my javascript  in the ascx file. How do i associate script functions to my control PorRadioClass?
0
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.

 
LVL 1

Expert Comment

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

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


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!
0
 
LVL 5

Author Comment

by:Peewee
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..
0
 
LVL 1

Accepted Solution

by:
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.
0

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