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

How to use a asp:ListItem as a javascript trigger?

I have an asp:RadioButtonList. If one of the items is selected, I'd like a
text field to appear.

I tried using an ONCHANGE event via the codebehind, but couldn't get that to
work. Plus, I'm thinking that might not be the most accessible way to handle
this anyways.

So...I wanted to just attach a javascript event to the specific listitem and
have that toggle the visibility of the text field (wrapped in a span).

I have this on my codebehind:

--------------------------------------
Protected WithEvents RadioButtonList_categories_9 As
System.Web.UI.HtmlControls.HtmlInputRadioButton

Private Sub Page_Load(...)
RadioButtonList_categories_9.Attributes.Add("onCha nge",
"toggle('categoryOther');")
End Sub
--------------------------------------

It doesn't work (Object reference not set to an instance of an object)

Now, I know my problem (I think). The issue is that the ID
'RadioButtonList_categories_9' isn't actually exposed in the HTML until the
page is rendered. Does that sound like the problem?

If so, can anyone recommend a way to accomplish this? I'd like to do it via
javascript, but I don't see a way to target a specific asp:listitem if the
ID doesn't appear until after page rendering.

-Darrel
Nov 19 '05 #1
2 2904
Hi,

I suppose that some sort of custom control might be needed for that case.
Here is a example of one.
http://www.asp.net/Forums/ShowPost.a...&PostID=253555

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"darrel" <no*****@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
I have an asp:RadioButtonList. If one of the items is selected, I'd like a
text field to appear.

I tried using an ONCHANGE event via the codebehind, but couldn't get that
to
work. Plus, I'm thinking that might not be the most accessible way to
handle
this anyways.

So...I wanted to just attach a javascript event to the specific listitem
and
have that toggle the visibility of the text field (wrapped in a span).

I have this on my codebehind:

--------------------------------------
Protected WithEvents RadioButtonList_categories_9 As
System.Web.UI.HtmlControls.HtmlInputRadioButton

Private Sub Page_Load(...)
RadioButtonList_categories_9.Attributes.Add("onCha nge",
"toggle('categoryOther');")
End Sub
--------------------------------------

It doesn't work (Object reference not set to an instance of an object)

Now, I know my problem (I think). The issue is that the ID
'RadioButtonList_categories_9' isn't actually exposed in the HTML until
the
page is rendered. Does that sound like the problem?

If so, can anyone recommend a way to accomplish this? I'd like to do it
via
javascript, but I don't see a way to target a specific asp:listitem if the
ID doesn't appear until after page rendering.

-Darrel

Nov 19 '05 #2
> I suppose that some sort of custom control might be needed for that case.

Ugh. I think I may just make it plain'ol HTML radio buttons, then. ;o)
Here is a example of one.
http://www.asp.net/Forums/ShowPost.a...&PostID=253555


Cool. I'll check that out!

-Darrel
Nov 19 '05 #3

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

Similar topics

5
by: John Davis | last post by:
When I create new documents in Dreamweaver, there are several choices for ASP creation: ASP JavaScript: run at client side?? ASP VBScript: run at server side?? ASP.NET C# ASP.NET VB I don't...
0
by: CGuy | last post by:
Hi, I have a RadioButtonList control in my aspx page which shows two radiobuttons - "Yes" and "No". Since my page is intended for international audience, I would like the texts "Yes" and "No" to...
2
by: fad | last post by:
How can I create a database access using asp+javascript withen the code?Is there (createdatabase)?If yes how can we use it? thanks for all -- fad...
5
by: Mark Rae | last post by:
Hi, Has the <asp:DropDownList> - <asp:ListItem> functionality changed in v2? In v1.1, the following works as expected: <asp:DropDownList ID="cmbStatus" Runat=server EnableViewState=False>...
0
by: John Smith | last post by:
This is what I am trying to do: <asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn Visible="False" DataField="id" ReadOnly="True"...
0
by: John Smith | last post by:
This is what I am trying to do: <asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn Visible="False" DataField="id" ReadOnly="True"...
3
by: Merennulli | last post by:
My problem child: <asp:dropdownlist id="ddlLimit" tabIndex="6" runat="server" EnableViewState="False" CssClass="query"> <asp:ListItem Value="100" Selected="True">100</asp:ListItem>...
4
by: zfarooq01 | last post by:
Asp Javascript language paging larger database record sets i am firmiliar with asp javascript and not asp VB. i can display the results ok, but if i return 100 records from my table i would...
7
by: Jim in Arizona | last post by:
Using this: <asp:ListItem Value="0"</asp:ListItem> as long as I have a value listed and leave the area between the tags blank, when viewed the DropDownList will show a 0 as a choice. I want it...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.