[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

Attribute not adding correctly on check boxes

Steve

3/2/2004 8:52:00 AM

I create a checkbox at run time.

public CheckBox makeCheckBox()
{
CheckBox cbC = new CheckBox();

cbC.Checked = true;

cbC.ID = "chkBoxAlpha;
cbC.Text = "Check this";
cbC.CssClass = "CheckBox";

cbC.Attributes["onchange"]= "dirty()";

return cbC;
}


I set the Attribute onchange to run a javascript program called dirty(). However, the rendered code is

<span class="CheckBox" onchange="dirty()">
<input id="chkBoxAlpha" type="checkbox" name="chkBoxAlpha" checked="checked" />
<label for="chkBoxAlpha">Check this</label>
</span>

As you can see, the onchange attribute is placed in the <span> tag which of course does not fire when I click on the box.

Any reason for this? It works fine for text boxes and drop down lists.

Steve

1 Answer

Teemu Keiski

3/2/2004 11:01:00 AM

0

Hi,

that is due to the way CheckBox renders (not sure why it is that way that
inside SPAN), but to be sure what is rendered you can use HTML server
control e.g <input type="checkbox" runat="server"> and so forth.


--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist


"Steve" <steve@I_dont_need_no_stickin_penis_pills.com> wrote in message
news:uS9FYODAEHA.1844@TK2MSFTNGP11.phx.gbl...
I create a checkbox at run time.

public CheckBox makeCheckBox()
{
CheckBox cbC = new CheckBox();

cbC.Checked = true;

cbC.ID = "chkBoxAlpha;
cbC.Text = "Check this";
cbC.CssClass = "CheckBox";

cbC.Attributes["onchange"]= "dirty()";

return cbC;
}


I set the Attribute onchange to run a javascript program called dirty().
However, the rendered code is

<span class="CheckBox" onchange="dirty()">
<input id="chkBoxAlpha" type="checkbox" name="chkBoxAlpha"
checked="checked" />
<label for="chkBoxAlpha">Check this</label>
</span>

As you can see, the onchange attribute is placed in the <span> tag which of
course does not fire when I click on the box.

Any reason for this? It works fine for text boxes and drop down lists.

Steve