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

D

darrel

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("onChange",
"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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top