marchemike
marchemike

Reputation: 3277

OnCheckedChanged not firing when clicked

I'm trying to run my OnCheckedChanged inside an itemtemplate, but it is not firing. What I did was I typed the OnCheckChanged in the asp:CheckBox tag and also typed the entire method manually. Would this affect the process??

 <asp:CheckBox runat="server" ID="uoCheckBoxTagtoVehicle" OnCheckedChanged="ChkChanged" AutoPostBack="true" Width="50px"   />

and my event:

protected void ChkChanged(object sender, EventArgs e)
{
    uoHiddenFieldVehicle.Value = "1";
}

Note: I'm using Visual studio 2008

Upvotes: 0

Views: 1405

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460138

Maybe you are databinding the page also on postback. You should do that only ...

if(!IsPostBack)
{
    DataBindPage(); // method which databinds your controls like GridView
}

Otherwise you prevent that events are triggered.

Upvotes: 1

Sam
Sam

Reputation: 2917

Since your control is inside a GridView (since you said ItemTemplate I assume you do) you can't use your approach to attach the event as you did. Because there will be multiple check boxes once you populate the GridView. Therefore, do the following

  1. In you GridView's DataBinding event find the CheckBox by ID (use FindControl method)
  2. Then attach the event OnCheckedChanged to the method you've written

Upvotes: 1

Related Questions