0

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

marchemike
  • 3,179
  • 13
  • 53
  • 96

2 Answers2

1

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.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
1

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
Sam
  • 2,917
  • 1
  • 15
  • 28