Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 23rd, 2004, 12:26 PM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Putting JavaScript Events on RadioButtonList Items

Is it possible to attach Javascript events to individual RadioButtonList Items? I've tried doing the Attributes.Add on the items collections like so:

        Me.Radiobuttonlist2.Items(0).Attributes.Add("onblu r", "DoPopupfrmDucted();")
        Me.Radiobuttonlist2.Items(2).Attributes.Add("onblu r", "DoPopupfrmDucted();")
        Me.Radiobuttonlist2.Items(1).Attributes.Add("onblu r", "DoPopupfrmFreeblow();")


But when I look at the source in the browser, they are never there.

Any help would be greatly appreciated.

Thanks,

Michael Schnell
 
Old April 22nd, 2004, 10:12 AM
Registered User
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I know this was a while back, but just wondering if you've figured out how to add events to these items? I'm having the exact same problem.

Anyone else know how to do this?

thanks in advance


Quote:
quote:Originally posted by MikeSchnell
 Is it possible to attach Javascript events to individual RadioButtonList Items? I've tried doing the Attributes.Add on the items collections like so:

        Me.Radiobuttonlist2.Items(0).Attributes.Add("onblu r", "DoPopupfrmDucted();")
        Me.Radiobuttonlist2.Items(2).Attributes.Add("onblu r", "DoPopupfrmDucted();")
        Me.Radiobuttonlist2.Items(1).Attributes.Add("onblu r", "DoPopupfrmFreeblow();")


But when I look at the source in the browser, they are never there.

Any help would be greatly appreciated.

Thanks,

Michael Schnell
 
Old June 21st, 2007, 09:27 AM
Registered User
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI,

I face the same problem. If u got any solution for this plz let me know.. It would be of much help for me...

Thanks in advance

Quote:
quote:Originally posted by MikeSchnell
 Is it possible to attach Javascript events to individual RadioButtonList Items? I've tried doing the Attributes.Add on the items collections like so:

        Me.Radiobuttonlist2.Items(0).Attributes.Add("onblu r", "DoPopupfrmDucted();")
        Me.Radiobuttonlist2.Items(2).Attributes.Add("onblu r", "DoPopupfrmDucted();")
        Me.Radiobuttonlist2.Items(1).Attributes.Add("onblu r", "DoPopupfrmFreeblow();")


But when I look at the source in the browser, they are never there.

Any help would be greatly appreciated.

Thanks,

Michael Schnell
 
Old June 21st, 2007, 04:55 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Have you tried, instead, adding the function to the Parent control?

Me.RadioButtonList2.Attributes.Add("onblur", "DoPopupfrmDucted();")

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old June 22nd, 2007, 04:33 AM
Registered User
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks for your reply...

I tried this as u said

Me.RadioButtonList2.Attributes.Add("onblur", "DoPopupfrmDucted();")

But the javascript event is attached for the Parent control as a whole...

My requirement is,

Whenever mouse is moved on a list item, i want to call a function say, showDescription(strListItemValue).

I want to pass the list current item's value to this function.

For example,

If mouse is moved on ListItem1, i shud call showDescription(listItem(1).value).

If mouse is moved on ListItem2, i shud call showDescription(listItem(2).value).

How can this be done?


 
Old October 5th, 2007, 10:38 PM
Registered User
 
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you found a solution for this!?

 
Old October 7th, 2007, 08:16 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

mmmk. The answer to this is that you can not use a RadioButtonList for the onMouseOver event, you need to use an individual RadioButton for the functionality you are asking for. So now comes the tricky part. If the radiobuttons in question are static, e.g. the data is not populated from a database etc, you simply can add the radio buttons to your page as you would any other server contorl:

Code:
 <asp:RadioButton id="rad1" runat="server" />
 <asp:RadioButton id="rad2" runat="server" />
Then, in code you would do something like:

Code:
if(!Page.IsPostBack)
{
 rad1.Attributes.Add("onMouseOver", "myJSFunction()");
 rad2.Attributes.Add("onMouseOver", "myJSFunction()");
}
Howerver, if the number of radiobuttons is NOT known at runtime you have to be a little bit more creative! On you .aspx page you would need some sort of container control like a placeholder or a panel and do something like: (I assume a Panel named panel1)

Code:
if(!Page.IsPostBack)
{
   for(int i = 0; i < [somevalue]; i++)
   {
      RadioButton rad = new RadioButton();
      rad.ID = i.ToString();
      rad.Attributes.Add("onMouseOver", "myJSFunction()");
      panel1.Controls.Add(rad);
   }
}
This will give you the ability to trigger JavaScript events when a user hovers over your radiobutton.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Validate Radiobuttonlist using Javascript roseforever C# 1 November 6th, 2008 04:55 AM
Runtime controls & Javascript events ITGeek ASP.NET 1.0 and 1.1 Professional 4 July 2nd, 2007 03:45 PM
putting values frm javascript f'n into session rajeshshinde Javascript How-To 1 December 18th, 2006 01:10 AM
putting **wider** items in the systray pgjuun2 General .NET 1 July 11th, 2005 10:41 AM
putting asp and javascript together gilgalbiblewheel Classic ASP Databases 0 April 5th, 2005 07:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.