Home All Groups Group Topic Archive Search About

Adding client side code to RadioButtonList control item???

Author
15 Mar 2006 8:50 PM
Dave
I'm trying to add some javascript to my RadioButtonList control below but it
never seems to render in the browser?  Is there an MS suggested work-around?

I eventually want to hide/show sections of the page using DHTML with this
javascript as buttons are clicked.

while (reader.Read())
{
ListItem item = new ListItem(reader["Title"].ToString());
if (reader["CheckedYn"].ToString() == "1")
{
item.Selected = true;
}

item.Attributes.Add("onclick", "alert('test');"); <--NEVER RENDERS???
radioButtonList.Items.Add(item);
                }

Author
15 Mar 2006 9:47 PM
Phillip Williams
'The radiobutton list server controls renders an HTMLTable that has rows;
each has a radiobutton.  There is no onclick event on the listitems for this
control.  If you want to do client-side programming you would have to do it
by programming the onclick event of the RadioButtonList itself, e.g.

//note: this javascript works only in IE
rbList1.Attributes.Add("onclick", "if
(window.event.srcElement.tagName=='INPUT') alert('you selected '+
window.event.srcElement.nextSibling.innerText);");


Show quoteHide quote
"Dave" wrote:

> I'm trying to add some javascript to my RadioButtonList control below but it
> never seems to render in the browser?  Is there an MS suggested work-around?
>
> I eventually want to hide/show sections of the page using DHTML with this
> javascript as buttons are clicked.
>
> while (reader.Read())
> {
> ListItem item = new ListItem(reader["Title"].ToString());
> if (reader["CheckedYn"].ToString() == "1")
> {
> item.Selected = true;
> }
>
> item.Attributes.Add("onclick", "alert('test');"); <--NEVER RENDERS???
> radioButtonList.Items.Add(item);
>                 }