[RESOLVED]Displays the same message even i use to change the message in script

Hello all,

I want the same thing as it is in MessageBox in asp.net i.e.

if dialog result =yes

// codeif dialog result ==no


So i used :

 if (!ReturnValue())

 string strconfirm = "<script>if(!window.confirm(‘Continue in demo mode?‘)){window.location.href=’Default.aspx’}</script>";
                            CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);


bool ReturnValue()
        return false;

But problem is that the message continue in demo mode doesn’t display, it displays only Are you sure?

try this

<html xmlns="http://www.w3.org/1999/xhtml">
<script type = "text/javascript">
    function Confirm() {
        var confirm_value = document.createElement("INPUT");
        confirm_value.type = "hidden";
        confirm_value.name = "confirm_value";
        if (confirm("Do you want to save data?")) {
            confirm_value.value = "Yes";
        } else {
            confirm_value.value = "No";
<form id="form1" runat="server">
  <asp:Button ID="btnConfirm" runat="server" 
 OnClick = "OnConfirm" Text ="Raise Confirm" OnClientClick = "Confirm()"/>

2) Codebehind

public void OnConfirm(object sender, EventArgs e)
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
this.Page.ClientScript.RegisterStartupScript(this.GetType(),"alert('You    clicked YES!')", true);
    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);


I am not using any button click event …………………..   it is on page load.

Hi jjbhatt_asp,

Welcome to the ASP.NET forum.

According to your description, I made a similar test on my web application, you could refer to the code below, hope it could helpful for you.

<script type="text/javascript" >
        function ConfirmMessage()
            var v = confirm("Are you want to close this Page?");
            if (v) {
                 //Do someting
            else {

In the page load event


If I misunderstand what you want, please let me know.


If you have any other questions about the ASP.NET, please feel free to post this forum.

Best Regards,


Leave a Reply