I have to do the validation on the Client Side when the one of the Radio Button Clicked from 3 of them. I know how to write the JavaScript Function but i am confused where i have to use this function by using ASP Radio Buttons.
I mean on which event of the RadioButton i have to fire the function of javascript. Because there is no any client side event like onClientClick on ASP radiobutton.
there must be a Button control on which you will be doing some functionality after entering your data. You have to call the javascript on that button. In short the final level of your page on which by click you will perform your operation.
Hope it will sort out your problem
Thanks and best regards,
Faraz Shah Khan
SFDC Certified Developer, MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
you will need the onmousedown javascript event. The visual studio IDE will tell you that it doesn't exist, but when your page is rendered out as html,
the radio button will become a 'input' and it will have the correct event attached on the client side.
Step2: You have to declare some button/imagebutton or somthing else to validate. I suppose you have button cmdSave for validation.
Step3: in code behind of page On Page Load, you have to call javascript function of validation. i.e
cmdSave.Attributes.Add(
"onClick",
"Javascript:checkFlag()");
Step4: You have to declare function checkFlag() in your aspx page. i.e
function
checkFlag()
{
event.returnValue =
false;
var DNR = document.getElementById('<%= RadioDNR.ClientID %>').checked;
var RE = document.getElementById('<%= RadioRE.ClientID %>').checked;
var RI = document.getElementById('<%= RadioRI.ClientID %>').checked;
if (DNR ==
false && RE == false && RI ==
false)
{
alert (
'Please Specify one of the Flags');
}
else
{
event.returnValue =
true;
}
}
You have to do nothing else. I am sure it will resolve your problem. If this is the solution of your problem, please mark this post as resolved. Thanks
Ya, this is the right way but i don't want to fired the function on any button clicked events. I want to do this using Click events on RadioButton. So what i have to do.
HI i am used as u specified but the problem is after getting the client response then the server event is not raising...
My objective is on clicking radiobutton then confirm must popup and if user press ok then the server event of radiobutton must raise otherwise it should not..
And i assigned the javascript funtion to radiobutton control thru control.attribute.add(onclick,return funname()) and in server event i wrote some code but is not raising even the user selects OK from confirm button
I know this thread is old, but for everyone's reference:
The radio button is rendered as <span><input><label></span> ( when text is set to display on the right).
By default, the Radiobutton.Attributes.Add() method will add attributes to the <span>, and in response to selarom's post, "onselect" is not a valid javascript event for the span element.
The radiobutton and checkbox both support two additional Attribute collections: InputAttributes (for attributes to add to the radio button or checkbox) and LabelAttributes (for attributes to be added to the text of the radio button).
So for selarom, use: rad.InputAttributes.Add("onselect", "myJsFunction()")
---------------------------------------
MCP - Web Based Client Development .NET 2.0
SPPatel
Member
7 Points
75 Posts
How to Use Javascript with ASP RadioButton?
Mar 19, 2007 05:06 AM|LINK
Hello,
I have to do the validation on the Client Side when the one of the Radio Button Clicked from 3 of them. I know how to write the JavaScript Function but i am confused where i have to use this function by using ASP Radio Buttons.
I mean on which event of the RadioButton i have to fire the function of javascript. Because there is no any client side event like onClientClick on ASP radiobutton.
So, Please help me to solve this problem.
Thanks
farazsk11
Star
8347 Points
1384 Posts
Re: How to Use Javascript with ASP RadioButton?
Mar 19, 2007 08:14 AM|LINK
Hi,
there must be a Button control on which you will be doing some functionality after entering your data. You have to call the javascript on that button. In short the final level of your page on which by click you will perform your operation.
Hope it will sort out your problem
Thanks and best regards,
SFDC Certified Developer, MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
SPPatel
Member
7 Points
75 Posts
Re: How to Use Javascript with ASP RadioButton?
Mar 19, 2007 01:57 PM|LINK
KBrocksi_SEC
Contributor
3382 Points
627 Posts
Re: How to Use Javascript with ASP RadioButton?
Mar 19, 2007 02:13 PM|LINK
Hi SPPatel,
you will need the onmousedown javascript event. The visual studio IDE will tell you that it doesn't exist, but when your page is rendered out as html,
the radio button will become a 'input' and it will have the correct event attached on the client side.
Something like this...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>test</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <script type="text/javascript"> function clickCheck(obj) { if (obj.checked) { alert("Already checked"); } } </script> <style type="text/css"></style> </head> <body> <input type="radio" onmousedown="clickCheck(this)" name="Radio1" /><br /> <input type="radio" name="Radio2" /> </body> </html>fahiemulleh
Member
232 Points
91 Posts
Re: How to Use Javascript with ASP RadioButton?
Mar 19, 2007 03:00 PM|LINK
Hi. Suppose you have 3 Radiobuttons.. You will be validating on some button control. Please find below how to do it step by step.
Step1: Setup your radio buttons on aspx page.
<strong> Some Heading</strong>
<asp:RadioButton ID="Radio1" GroupName="Flag" runat="server" Text="DNR" /> <asp:RadioButton ID="Radio2" GroupName="Flag" runat="server" Text="RE" />
<asp:RadioButton ID="Radio3" GroupName="Flag" runat="server" Text="RI" />Step2: You have to declare some button/imagebutton or somthing else to validate. I suppose you have button cmdSave for validation.
Step3: in code behind of page On Page Load, you have to call javascript function of validation. i.e
cmdSave.Attributes.Add(
"onClick", "Javascript:checkFlag()");Step4: You have to declare function checkFlag() in your aspx page. i.e
function
checkFlag(){
event.returnValue = false; var DNR = document.getElementById('<%= RadioDNR.ClientID %>').checked; var RE = document.getElementById('<%= RadioRE.ClientID %>').checked; var RI = document.getElementById('<%= RadioRI.ClientID %>').checked;
if (DNR == false && RE == false && RI == false){
alert (
'Please Specify one of the Flags');}
else{
event.returnValue = true;}
}
You have to do nothing else. I am sure it will resolve your problem. If this is the solution of your problem, please mark this post as resolved. Thanks
SPPatel
Member
7 Points
75 Posts
Re: How to Use Javascript with ASP RadioButton?
Mar 19, 2007 07:07 PM|LINK
Hi fahiemulleh ,
Ya, this is the right way but i don't want to fired the function on any button clicked events. I want to do this using Click events on RadioButton. So what i have to do.
SPPatel
Member
7 Points
75 Posts
Re: How to Use Javascript with ASP RadioButton?
Mar 19, 2007 07:16 PM|LINK
Hi KBrocksi_SEC,
Thanks for the reply. But after that how can i get the value(is it checked or not) of html radio on my .aspx page.
Please reply me.
Thanks
fahiemulleh
Member
232 Points
91 Posts
Re: How to Use Javascript with ASP RadioButton?
Mar 20, 2007 06:23 AM|LINK
You have an event CheckedChanged of Radiobutton. Call javascript validation function from this event. i.e
Radio1.Attributes.Add("onClick","javascript:checkFlags()")
let me know if the problem is still not resolved and if resolved, please mark this post as resolved.
gspandian
Member
13 Points
26 Posts
Re: How to Use Javascript with ASP RadioButton?
Jul 13, 2007 10:16 AM|LINK
HI i am used as u specified but the problem is after getting the client response then the server event is not raising...
My objective is on clicking radiobutton then confirm must popup and if user press ok then the server event of radiobutton must raise otherwise it should not..
And i assigned the javascript funtion to radiobutton control thru control.attribute.add(onclick,return funname()) and in server event i wrote some code but is not raising even the user selects OK from confirm button
why the event is not raising?
regards
pandi G S
ps2goat
Star
10845 Points
1977 Posts
Re: How to Use Javascript with ASP RadioButton?
Nov 23, 2010 06:43 PM|LINK
I know this thread is old, but for everyone's reference:
The radio button is rendered as <span><input><label></span> ( when text is set to display on the right).
By default, the Radiobutton.Attributes.Add() method will add attributes to the <span>, and in response to selarom's post, "onselect" is not a valid javascript event for the span element.
The radiobutton and checkbox both support two additional Attribute collections: InputAttributes (for attributes to add to the radio button or checkbox) and LabelAttributes (for attributes to be added to the text of the radio button).
So for selarom, use: rad.InputAttributes.Add("onselect", "myJsFunction()")
MCP - Web Based Client Development .NET 2.0