adding attribute to checkbox

B

BK Kim

hello.

I am trying to add an attribute on the checkbox.

In my C# code,

chkText.Attributes.Add("onChange", "window.alert('hello');return false");

But the result is like below on the web browser,

<span onChange="window.alert('bk');return false"><input id="chkTest"
type="checkbox" name="chkTest" /><label for="chkTest">test</label></span>

Anyone know how to add that onChange event on the input tag???

Thanx in advance
 
J

John Saunders

BK Kim said:
hello.

I am trying to add an attribute on the checkbox.

In my C# code,

chkText.Attributes.Add("onChange", "window.alert('hello');return false");

But the result is like below on the web browser,

<span onChange="window.alert('bk');return false"><input id="chkTest"
type="checkbox" name="chkTest" /><label for="chkTest">test</label></span>

Anyone know how to add that onChange event on the input tag???

You can't. The CheckBox control is the span, not the input tag.

You'll have to use <input type="checkbox" runat="server"> instead.
 

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,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top