2

I am having a page where i need to confirm whether to show updated grid or not

I am calling a javascript function using

ScriptManager.RegisterStartupScript(this, typeof(string), "Error", "confirm('Are u sure');", true);

What I want to know is how to get the return value of confirm in C# code behind.

Kyle Trauberman
  • 25,414
  • 13
  • 85
  • 121
Vinod
  • 4,672
  • 4
  • 19
  • 26
  • 1
    You can't get the return value of a client-side JavaScript function directly in server-side C# code-behind, that value would need to be submitted. – nnnnnn Jun 16 '12 at 06:21
  • usually with confirms you just cancel the event in the case a user clicked "no". You dont have to submit the form at all in this case – YavgenyP Jun 16 '12 at 06:23

2 Answers2

4

Instead of this

ScriptManager.RegisterStartupScript(this, typeof(string), "Error", "confirm('Are u sure');", true);

use this

ScriptManager.RegisterStartupScript(this, typeof(string), "Error", "ConfirmUser('Are u sure');", true);

<script type='javascript'>
 function ConfirmUser(msg)
 {
  if(confirm(msg))
    __doPostBack('','');
 }
<script>

see following links to know more about __doPostBack

1 2

Community
  • 1
  • 1
yogi
  • 19,175
  • 13
  • 62
  • 92
3

I am having a page where i need to confirm whether to show updated grid or not

You may prevent the postback when use choose Cancel button of confirm dialog.

<asp:Button ID="Button1" runat="server" 
            OnClientClick="return confirm('Are you sure to populate the list?');" 
            Text="Button" onclick="Button1_Click" />
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186