473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How do I tie a control to a JavaScript function

I'm new to WebForms and struggling with very basic stuff at the moment. I am
trying to figure out how to detect a radiobutten click state using
JavaScript.

The following OnCheckedChanged code fails at runtime:

<HTML>

<HEAD>

<title>WebForm1</title>

<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">

<meta content="C#" name="CODE_LANGUAGE">

<meta content="JavaScript" name="vs_defaultClientScript">

<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">

</HEAD>

<body>

<form id="Form1" method="post" runat="server">

<P>

<asp:RadioButton id="RadioButton1" runat="server" Checked="True"
Text="Purchase" GroupName="rb3"></asp:RadioButton><BR>

<asp:RadioButton id="RadioButton2" runat="server" Text="Refi"
GroupName="rb3" OnCheckedChanged="changed(this);"></asp:RadioButton></P>

<P>

</form>

<SCRIPT>

function changed(rb){

document.write("Click event");

}

</SCRIPT>

</P>

</body>

</HTML>
Nov 18 '05 #1
5 3253

OnCheckedChanged is a server side event. You need to implement the function
on the runat='server' codeblock.

You might want to look in the QuickStart tutorials. (usually installed when
you install .NET SDK).
--
Girish Bharadwaj
http://msmvps.com/gbvb
"Jason" <nf*@nospam.com> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
I'm new to WebForms and struggling with very basic stuff at the moment. I am trying to figure out how to detect a radiobutten click state using
JavaScript.

The following OnCheckedChanged code fails at runtime:

<HTML>

<HEAD>

<title>WebForm1</title>

<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">

<meta content="C#" name="CODE_LANGUAGE">

<meta content="JavaScript" name="vs_defaultClientScript">

<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">

</HEAD>

<body>

<form id="Form1" method="post" runat="server">

<P>

<asp:RadioButton id="RadioButton1" runat="server" Checked="True"
Text="Purchase" GroupName="rb3"></asp:RadioButton><BR>

<asp:RadioButton id="RadioButton2" runat="server" Text="Refi"
GroupName="rb3" OnCheckedChanged="changed(this);"></asp:RadioButton></P>

<P>

</form>

<SCRIPT>

function changed(rb){

document.write("Click event");

}

</SCRIPT>

</P>

</body>

</HTML>

Nov 18 '05 #2
Oh, btw: onCheckedChanged is a Check box event.. Fyi.

--
Girish Bharadwaj
http://msmvps.com/gbvb
"Jason" <nf*@nospam.com> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
I'm new to WebForms and struggling with very basic stuff at the moment. I am trying to figure out how to detect a radiobutten click state using
JavaScript.

The following OnCheckedChanged code fails at runtime:

<HTML>

<HEAD>

<title>WebForm1</title>

<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">

<meta content="C#" name="CODE_LANGUAGE">

<meta content="JavaScript" name="vs_defaultClientScript">

<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">

</HEAD>

<body>

<form id="Form1" method="post" runat="server">

<P>

<asp:RadioButton id="RadioButton1" runat="server" Checked="True"
Text="Purchase" GroupName="rb3"></asp:RadioButton><BR>

<asp:RadioButton id="RadioButton2" runat="server" Text="Refi"
GroupName="rb3" OnCheckedChanged="changed(this);"></asp:RadioButton></P>

<P>

</form>

<SCRIPT>

function changed(rb){

document.write("Click event");

}

</SCRIPT>

</P>

</body>

</HTML>

Nov 18 '05 #3
Use Click events with the radio (or simple Submit buttons) and then use
Radio.Checked flag to check which of the radio buttons is checked.

--
Girish Bharadwaj
http://msmvps.com/gbvb
"Tampa .NET Koder" <Ta***********@discussions.microsoft.com> wrote in
message news:4E**********************************@microsof t.com...
Since OnCheckedChange is a server side event, how would you call a JavaScript function on the client? How to determine which option was clicked?

"Girish Bharadwaj" wrote:

OnCheckedChanged is a server side event. You need to implement the function on the runat='server' codeblock.

You might want to look in the QuickStart tutorials. (usually installed when you install .NET SDK).
--
Girish Bharadwaj
http://msmvps.com/gbvb
"Jason" <nf*@nospam.com> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
I'm new to WebForms and struggling with very basic stuff at the moment. I
am
trying to figure out how to detect a radiobutten click state using
JavaScript.

The following OnCheckedChanged code fails at runtime:

<HTML>

<HEAD>

<title>WebForm1</title>

<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">

<meta content="C#" name="CODE_LANGUAGE">

<meta content="JavaScript" name="vs_defaultClientScript">

<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">

</HEAD>

<body>

<form id="Form1" method="post" runat="server">

<P>

<asp:RadioButton id="RadioButton1" runat="server"

Checked="True" Text="Purchase" GroupName="rb3"></asp:RadioButton><BR>

<asp:RadioButton id="RadioButton2" runat="server" Text="Refi"
GroupName="rb3" OnCheckedChanged="changed(this);"></asp:RadioButton></P>
<P>

</form>

<SCRIPT>

function changed(rb){

document.write("Click event");

}

</SCRIPT>

</P>

</body>

</HTML>


Nov 18 '05 #4
One easy way to accomplish this is adding to the attributes collection
of the control.

In you PageLoad, try adding

RadioButton1.Attributes.Add("onclick", "changed()")
Joel Cade, MCSD .Net, MCAD, MCP
Fig Tree Solutions, LLC
http://www.figtreesolutions.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5
That did the trick. For the life of me, I couldn't find anything on how to
do this. The best I could come up with required an automatic postback where
the event could be handled in the code behind... that just didn't seem
effecient for my needs to make certain controls visible/hidden depending on
options selected.

Thanks.

<Joel Cade>; "MCSD" <jo**@nospam.figtreesolutions.com> wrote in message
news:O2**************@TK2MSFTNGP09.phx.gbl...
One easy way to accomplish this is adding to the attributes collection
of the control.

In you PageLoad, try adding

RadioButton1.Attributes.Add("onclick", "changed()")
Joel Cade, MCSD .Net, MCAD, MCP
Fig Tree Solutions, LLC
http://www.figtreesolutions.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3"...
2
by: Jakub Gutkowski | last post by:
Hi, Dose anybody knows how to call JavaScript function in C# Windows User Control? I use Windows User Control as smth like ActiveX, 'coz I need to call
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
6
by: Nedu N | last post by:
Hi, I want to have confirmation(Yes/No) on a button of the webform in which there are many validation controls. I want all the validation controls to be triggered first and then Yes/No...
4
by: moondaddy | last post by:
Is there a asp.net validator control that validates the length of the text being entered or does everyone just write jscript for this? -- moondaddy@nospam.com
4
by: Barb | last post by:
I have a user control as my Save button for my page. When the Save button is clicked, I want some client-side validation to take place from a javascript function in the page, and then I'd like the...
3
by: Ant | last post by:
I'm building a Web user control that has several public functions. Can I fire them from the client side? for example Javascript and an HTML button
1
by: Jorge Ponte | last post by:
hi I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button and open a popup (I use javascript for...
1
by: avp | last post by:
Hi, We have an ASP.NET 2.0 (C#) application that has a web form with a CheckBoxList control and a CustomValidator control. The CustomValidator control is used to validate that at least one...
3
by: =?Utf-8?B?Qw==?= | last post by:
Hi, I have a user control which I use on all my pages. The control is situated on the top of my page (sits on my master page). For some long pages the user has to scroll back up to the top of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.