Mata

Mata

  • NA
  • 46
  • 34.5k

Gridview confirm checkbox javascript problem

Dec 22 2011 4:07 PM
I want to confirm with javascript checked true before triggering checkedChanged event on server side

this is filling checkbox in edit mode

private void potvrdaGreskaReprint(GridViewRowEventArgs e)
    {
        CheckBox ch = (CheckBox)e.Row.FindControl("cbGreska");
        ch.Attributes.Add("onclick", "confirmation(" + ch.UniqueID + ")");
    }

next is javascript function:

<script language="javascript" type="text/javascript">
    function  confirmation(checkbox) {
        if (checkbox.checked == true) {
            var answer = confirm('Really confirm');


            if (answer) {
                __doPostBack(checkbox, '');
                return true;
            }
            else {
                checkbox.checked = false; return false;
            }
        }
    }
     
    </script>

defining checkbox in gridview:

<asp:TemplateField HeaderText="Greška" ItemStyle-HorizontalAlign="Center" SortExpression="greska">
                    <EditItemTemplate>
                        <asp:CheckBox ID="cbGreska" runat="server" Checked='<%# Bind("greska") %>' OnCheckedChanged="cbGreska_OnCheckedChanged" />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lbGreska" runat="server" Text='<%# Eval("greska") %>' Visible="false"></asp:Label>
                        <asp:Image ID="imgGreska" runat="server" />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                </asp:TemplateField>

Finally checked changed event on server side

protected void cbGreska_OnCheckedChanged(object sender, EventArgs e)
    {
        CheckBox ch = (CheckBox)sender;


        if (ch.Checked)
        {......


So basicly I want to trigger checked Changed event with javascript

On debugging I get "Error: Object doesn't support property or method 'replace' "

at   __doPostBack(checkbox, ''); line in javascript function





Answers (1)