473,395 Members | 2,783 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,395 software developers and data experts.

asp:RadioButton runat="server" - want to react to click event on client side

I've wasted the whole day trying things and researching, but nothing is
working. I would *greatly* appreciate if someone can give me the
solution to this problem.

I'm using the .NET Framework 2.0 in C# with a Master page and
additional .aspx pages with .cs code-behind pages in Windows XP.

In an .aspx page I have declared a control as follows:
<asp:RadioButton runat="server" GroupName="rbtnS0"
ID="rbtnS0start" />

I want to do some event-side work whenever this RadioButton is clicked.
I've tried everything I've found, e.g., putting
rbtnS0start.Attributes.Add("OnClick", "rbtnS0start_Click();");
in the .cs file's Page_Load event, and then specifying
<script type="javascript">
function rbtnS0start_Click()
alert('test');
</script>
in the asp:Content section of the .aspx file. I get an "error on page"
from IE6 whenever I click that button. I've tried dozens of
combinations of things. (Unfortunately, there is no OnClick attribute
for an asp:RadioButton.)

Can someone *please* give me the code (and where it goes) so that I can
do client-side work when the user clicks an asp:RadioButton control?

Thank you *so much* to anyone who helps!

Jan 24 '07 #1
5 9412
you need to legal javascript syntax to define the function.

<script type="javascript">
function rbtnS0start_Click() {
alert('test');
}
</script>
Barry wrote:
I've wasted the whole day trying things and researching, but nothing is
working. I would *greatly* appreciate if someone can give me the
solution to this problem.

I'm using the .NET Framework 2.0 in C# with a Master page and
additional .aspx pages with .cs code-behind pages in Windows XP.

In an .aspx page I have declared a control as follows:
<asp:RadioButton runat="server" GroupName="rbtnS0"
ID="rbtnS0start" />

I want to do some event-side work whenever this RadioButton is clicked.
I've tried everything I've found, e.g., putting
rbtnS0start.Attributes.Add("OnClick", "rbtnS0start_Click();");
in the .cs file's Page_Load event, and then specifying
<script type="javascript">
function rbtnS0start_Click()
alert('test');
</script>
in the asp:Content section of the .aspx file. I get an "error on page"
from IE6 whenever I click that button. I've tried dozens of
combinations of things. (Unfortunately, there is no OnClick attribute
for an asp:RadioButton.)

Can someone *please* give me the code (and where it goes) so that I can
do client-side work when the user clicks an asp:RadioButton control?

Thank you *so much* to anyone who helps!
Jan 24 '07 #2
"bruce barker" <no****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
you need to legal javascript syntax to define the function.

<script type="javascript">
Or even

<script type="text/javascript">

if you want to be XHTML-compliant...
Jan 25 '07 #3
Oh what a difference a couple of curly braces make! Imagine 9 hours
wasted because I didn't have the curly braces :-(. Thank you both very
much!!

On Jan 24, 8:14 pm, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"bruce barker" <nos...@nospam.comwrote in messagenews:%2****************@TK2MSFTNGP05.phx.gb l...
you need to legal javascript syntax to define the function.
<script type="javascript">Or even

<script type="text/javascript">

if you want to be XHTML-compliant...
Jan 25 '07 #4
Ok, now I want to work with my client controls (instead of just popping
up an alert). For instance when they click rbtnS0start I want the
javascript on the client to set rbtnS1start (another asp:RadioButton)
to be 'checked=true'. I've tried things like: rbtnS1start.Checked =
true; but apparently that's not right because it doesn't check the
button or execute the rest of my javascript.

Obviously I'm quite new to client-side scripting, so any help/pointers
you can provide would be most appreciated. (Btw, I'm on the clock, so
the sooner someone will help me the better.)

Thank you!!

On Jan 25, 1:17 pm, "Barry" <dys...@gmail.comwrote:
Oh what a difference a couple of curly braces make! Imagine 9 hours
wasted because I didn't have the curly braces :-(. Thank you both very
much!!

On Jan 24, 8:14 pm, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"bruce barker" <nos...@nospam.comwrote in messagenews:%2****************@TK2MSFTNGP05.phx.gb l...
you need to legal javascript syntax to define the function.
<script type="javascript">Or even
<script type="text/javascript">
if you want to be XHTML-compliant...- Hide quoted text -- Show quoted text -
Jan 26 '07 #5
Well I finally figured out a way to do this. I couldn't get the
document.getElementById thing to work, and I'm sure there must be a
more concise way to do this (for example, passing an array) but I don't
know Javascript well enough. At this point, I don't care. I got it to
work, so I'm supplying the complete solution for the other poor souls
out there trying to do the same thing. As a reminder, what this does
is, when the user clicks the asp:RadioButton whose ASP ID is
rbtnS0start, I want the client to run Javascript in the .aspx page so
that the asp:RadioButtons named rbtnS1start thru rbtnS6start
automatically get checked.

In the code-behind page I have this code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
rbtnS0start.Attributes.Add("OnClick", "rbtnS0start_Click("
+
rbtnS1start.ClientID + "," +
rbtnS2start.ClientID + "," +
rbtnS3start.ClientID + "," +
rbtnS4start.ClientID + "," +
rbtnS5start.ClientID + "," +
rbtnS6start.ClientID +
");");
}
}

In the .aspx page, I included the following code just before the
</asp:Contenttag (which is the last tag on the page)...
<script type="text/javascript">
function rbtnS0start_Click(b1,b2,b3,b4,b5,b6)
{
b1.checked = true;
b2.checked = true;
b3.checked = true;
b4.checked = true;
b5.checked = true;
b6.checked = true;
}
</script>

Could this have possibly been made any harder to do!!??

On Jan 26, 9:29 am, "Barry" <dys...@gmail.comwrote:
Ok, now I want to work with my client controls (instead of just popping
up an alert). For instance when they click rbtnS0start I want the
javascript on the client to set rbtnS1start (another asp:RadioButton)
to be 'checked=true'. I've tried things like: rbtnS1start.Checked =
true; but apparently that's not right because it doesn't check the
button or execute the rest of my javascript.

Obviously I'm quite new to client-side scripting, so any help/pointers
you can provide would be most appreciated. (Btw, I'm on the clock, so
the sooner someone will help me the better.)

Thank you!!

On Jan 25, 1:17 pm, "Barry" <dys...@gmail.comwrote:
Oh what a difference a couple of curly braces make! Imagine 9 hours
wasted because I didn't have the curly braces :-(. Thank you both very
much!!
On Jan 24, 8:14 pm, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"bruce barker" <nos...@nospam.comwrote in messagenews:%2****************@TK2MSFTNGP05.phx.gb l...
you need to legal javascript syntax to define the function.
<script type="javascript">Or even
<script type="text/javascript">
if you want to be XHTML-compliant...- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -
Jan 26 '07 #6

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

Similar topics

2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
2
by: Lubomir | last post by:
Hi, I have a BoundColumn in a DataGrid: <asp:BoundColumn DataField="lastname" SortExpression="lastname" ReadOnly="True" HeaderText="Last Name"></asp:BoundColumn> Column is sorted. I am...
4
by: COHENMARVIN | last post by:
I'm a asp programmer starting out with asp.net. I understand that an asp form can post to its own page and that this allows validation of form fields on the server. But suppose all the controls...
3
by: Jaime Stuardo | last post by:
Hi all... Both controls are server side. The former has more properties. Both may have associated events that are ran at server. Which one are recommended to use? is performance an issue? in...
4
by: Ryan | last post by:
Hello, I have a standard HTML button on an aspx web form that I have set to runat server. The button is named reset1 and its tag is as follows: <INPUT id="btnReset1" style="WIDTH: 60px;...
11
by: gunjan.mait | last post by:
hi, i wanted to know the exact use of runat="server" which is being used is ASP.NET why we every time need to use it, even when i want to do the work at client side? How to do simple processings...
1
by: mark4asp | last post by:
<form runat="server"automatically adds <divtag to code contained within. Is there a way to stop that? Mixing block-level elements with inline-level elements messes up the HTML becasuse that is...
2
by: Bob | last post by:
Hi, in aspx file, i defined this: <input id="Button2" type="button" value="button" runat="server" onclick="klik()"/> This 'onclick' event is a clientclick (starting the Javascript function...
4
by: Chris | last post by:
Hi, i 'm experimenting with postback and i tried that with a button server control and an Html input button but with runat="server". The button server control causes a postback, but not the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.