confirmSave alert box,cancel button functionality not working
-
Hi, I have written the following code in javascript and when cancel button is clicked in alert box, the record is getting saved and when again second time when cancel button is clicked the functionality of the cancel button in the alertbox is working fine.My issue is at the first time my cancel button is not working and my record is getting saved.can anybody let me know the solution of this issue. function confirmsave() { if(confirm("Are u sure u want to Save Record?")) { return true; } else { document.getElementById('<%=Label22.ClientID %>').innerHTML = "Cancel"; return false; } } <asputton ID="btnsave" runat="server" Style="z-index: 101; left: 420px; position: absolute; top: 37px" Text="Save" Width="64px" OnClientClick="javascript:return confirmsave();" OnClick="btnsave_Click" /> protected void btnsave_Click(object sender, EventArgs e) { if (Page.IsValid == true) { Label22.Visible = true; Label22.Text = " Record Saved "; } } Thanks Ramesh
-
Hi, I have written the following code in javascript and when cancel button is clicked in alert box, the record is getting saved and when again second time when cancel button is clicked the functionality of the cancel button in the alertbox is working fine.My issue is at the first time my cancel button is not working and my record is getting saved.can anybody let me know the solution of this issue. function confirmsave() { if(confirm("Are u sure u want to Save Record?")) { return true; } else { document.getElementById('<%=Label22.ClientID %>').innerHTML = "Cancel"; return false; } } <asputton ID="btnsave" runat="server" Style="z-index: 101; left: 420px; position: absolute; top: 37px" Text="Save" Width="64px" OnClientClick="javascript:return confirmsave();" OnClick="btnsave_Click" /> protected void btnsave_Click(object sender, EventArgs e) { if (Page.IsValid == true) { Label22.Visible = true; Label22.Text = " Record Saved "; } } Thanks Ramesh
Try above code
Kiran Banker
-
Hi, I have written the following code in javascript and when cancel button is clicked in alert box, the record is getting saved and when again second time when cancel button is clicked the functionality of the cancel button in the alertbox is working fine.My issue is at the first time my cancel button is not working and my record is getting saved.can anybody let me know the solution of this issue. function confirmsave() { if(confirm("Are u sure u want to Save Record?")) { return true; } else { document.getElementById('<%=Label22.ClientID %>').innerHTML = "Cancel"; return false; } } <asputton ID="btnsave" runat="server" Style="z-index: 101; left: 420px; position: absolute; top: 37px" Text="Save" Width="64px" OnClientClick="javascript:return confirmsave();" OnClick="btnsave_Click" /> protected void btnsave_Click(object sender, EventArgs e) { if (Page.IsValid == true) { Label22.Visible = true; Label22.Text = " Record Saved "; } } Thanks Ramesh
The code block written looks good and I used the same code block and found that clicking "cancel" working as expected. In your situation if it is not working then try following (1) I suspect that following line might be creating problem and as a result you are not getting correct result.
document.getElementById('<%=Label22.ClientID %>').innerHTML = "Cancel";
Change the line to check whether it can find that object as follows, ( I suspect that following line could give 'null' in your actual code block,alert(document.getElementById('<%=Label22.ClientID %>'));
Let me know if it helps,
Thanks, Arindam D Tewary