In InsertItem Template of a FormView, I want to execute a JavaScript on "onChange" event of a textbox. I have written following code for this
protected void myFormView_ItemCommand(object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "New" || e.CommandName == "Edit")
{
TextBox txtStaffName = ((TextBox)myFormView.FindControl("txtStaffName"));
txtStaffName.Attributes.Add("onChange", "dataChanged();");
}
}
The dataChanged() javascript method is running in Edit mode of formview but is not working in Insert mode!!!
The control name in both insert and edit template is the same i.e. txtStaffName
Please help where should i place this code. Or how should i add this attribute with this control.
Thank you