I have a datagrid with checkboxes and I can check/uncheck the
checkboxes to update a database by calling my oncheckchanged function.
I would like to add popup asking the users if they are sure they want
to proceed.
I have written a javascript function named confirm_duplica te and it
works as expected - it checks/unchecks checkboxes depending on user
response.
The problem is when I use the javascript alert the checkbox
autopostback does not occurr and my oncheckchanged function is never
called. Can anyone provide any clues of what I need to do? Thanks
asp code:
function confirm_duplica te()
{
if (confirm("Are you sure you want to \nchange this
selection?")==t rue)
return true;
else
return false;
}
<ItemTemplate >
<asp:CheckBox id=chk runat="server" AutoPostBack="t rue"
onCheckedChange d="oncheckchang ed"
Checked='<%#IsC heck(DataBinder .EvalContainer. DataItem, "Duplicate" ))
%>'>
</asp:CheckBox>
</ItemTemplate>
C# code:
void myDataGrid_Item Created(object
sender,System.W eb.UI.WebContro ls.DataGridItem EventArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
CheckBox _chk = (CheckBox)e.Ite m.FindControl(" chk");
_chk.Attributes .Add("onclick", "return confirm_duplica te();");
}
}
public void oncheckchanged( object source, System.EventArg s e)
{
code to update database
}
protected bool IsCheck(object objInc)
{
helper code to check/uncheck datagrid column on page load
}