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.

2
  • 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. Commented Jun 16, 2012 at 6: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 Commented Jun 16, 2012 at 6:23

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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" />

1 Comment

But i think vinod want to show confirm box after some manipulation on server side...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.