Thursday, March 29, 2012

Newbie: JavaScript validation on <Asp:CheckBox click

It might be a simple question.
I am very new to ASP.Net 2, and stuck with a problem.
How can I execute a client side JavaScript function on CheckBox click.
I am able to execute function at server, But I don't know how to validate at
client side before going to server.
This code is within a GridView
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"
Checked='<%# Bind("OpenConnection") %> '
Enabled="True"
OnCheckedChanged="OpenConnection_Clicked" AutoPostBack="True" />
</ItemTemplate>
When I put onClick="Javascript:FunctionName" within the tag, it says:
Validation (ASP.Net): Attribute'onclick' is not a valid attribute for
element 'CheckBox'.
Please help me.
I'll appreciate your help.
Thanks, RobIt looks like button would better suit the purpose - usually when you want t
o
perform an action (as you do with AutoPostBack="true") a button or a link is
the way to go, and you could use OnClientClick property to inject your
javascript
HTH
"Rob" wrote:

> It might be a simple question.
> I am very new to ASP.Net 2, and stuck with a problem.
> How can I execute a client side JavaScript function on CheckBox click.
> I am able to execute function at server, But I don't know how to validate
at
> client side before going to server.
>
> This code is within a GridView
> <ItemTemplate>
> <asp:CheckBox ID="CheckBox1" runat="server"
> Checked='<%# Bind("OpenConnection") %> '
> Enabled="True"
> OnCheckedChanged="OpenConnection_Clicked" AutoPostBack="True" />
> </ItemTemplate>
> When I put onClick="java script:FunctionName" within the tag, it says:
> Validation (ASP.Net): Attribute'onclick' is not a valid attribute for
> element 'CheckBox'.
> Please help me.
> I'll appreciate your help.
> Thanks, Rob
>
>

0 comments:

Post a Comment