D
David Pifer via .NET 247
Hello,
Fooling around with ASP.Net and wanted to know if this ispossible...I wanted to attach a client event to a ASP:Checkboxcontrol. I got this to work by adding this line of code to theSub Page_Load
Code:
chkBoxProduct.Attributes.Add("OnClick", "testFunction();")
This function just displays an alert box that says the basic'Hello World!'
That is fine...I got this to work when I ran the WebForm1.aspxpage however, this is what I can not get to work let's say Ichange the JavaScript function that is in between the <HEAD>tags on the HTML page to have a parameter and for simplicitywant to show the name of the checkbox I am checking.
Code:
function testFunction(chkBox)
{
alert(chkBox.Name);
}
Here is the code from the WebForm1.aspx page
Code:
<asp:CheckBox ID="chkBoxProduct" OnClick="testFunction(this)"Runat="server"></asp:CheckBox>
and then I try to do this in the Sub Page_Load
Code:
chkBoxProduct.Attributes.Add("OnClick", "testFunction(chkBox);")
When I run the program and click on the checkbox I get 'chkBox isundefined'. So can I only add attributes to the controls thattake no parameters?
Thanks for the help.
Dave Pifer
Fooling around with ASP.Net and wanted to know if this ispossible...I wanted to attach a client event to a ASP:Checkboxcontrol. I got this to work by adding this line of code to theSub Page_Load
Code:
chkBoxProduct.Attributes.Add("OnClick", "testFunction();")
This function just displays an alert box that says the basic'Hello World!'
That is fine...I got this to work when I ran the WebForm1.aspxpage however, this is what I can not get to work let's say Ichange the JavaScript function that is in between the <HEAD>tags on the HTML page to have a parameter and for simplicitywant to show the name of the checkbox I am checking.
Code:
function testFunction(chkBox)
{
alert(chkBox.Name);
}
Here is the code from the WebForm1.aspx page
Code:
<asp:CheckBox ID="chkBoxProduct" OnClick="testFunction(this)"Runat="server"></asp:CheckBox>
and then I try to do this in the Sub Page_Load
Code:
chkBoxProduct.Attributes.Add("OnClick", "testFunction(chkBox);")
When I run the program and click on the checkbox I get 'chkBox isundefined'. So can I only add attributes to the controls thattake no parameters?
Thanks for the help.
Dave Pifer