Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI
I am having a grid and a checkbox in the grid when checkbox is checked i want to call a javascript for confimation like are you sure and if user clicks on yes then i want to go for the server side using onchecked change. But javascript is firing but post back not happens when i call javascript .in normal case oncheckchange is calling.
Please help in this regards;
here is my code:
XML
<asp:GridView ID="GridView1" runat="server">
       <Columns>
       <asp:TemplateField>
       <ItemTemplate>
            <asp:CheckBox ID="chkBox" runat="server"
 oncheckedchanged="CheckBox1_CheckedChanged"
     AutoPostBack="true" onclick="javascript:return Ischecked(this)" />
       </ItemTemplate>
       </asp:TemplateField>
        <asp:TemplateField>
       <ItemTemplate>
           <%--<asp:Button ID="Button1" runat="server" Text="Button" CommandName="Hai"  CommandArgument='<%# ((GridViewRow) Container).RowIndex %>'/>--%>
       </ItemTemplate>
       </asp:TemplateField>
       </Columns>
       </asp:GridView>

in javascript
C#
function Ischecked(ID) {
        var message1;
        if (ID.checked == true) {
            message1 = "ARE U Sure";
        }
        return confirm(message1) ;
    }
Posted
Updated 10-Jan-12 2:20am
v2

Try This:

Change your javascript function to:

C#
function Ischecked(ID) {
        var message1;
        if (ID.checked == true) {
            message1 = "ARE U Sure";
        }
        if(confirm(message1))
        {
             __doPostBack();
        }
    }


This may solve your problem.
 
Share this answer
 
XML
<b>in grid view for check box change this line</b>

<asp:CheckBox ID="chkBox" runat="server"
 oncheckedchanged="CheckBox1_CheckedChanged"
     AutoPostBack="true" onclientclick="javascript:return Ischecked(this)" />
       </ItemTemplate>


this may solve your problem
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900