[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

//code

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">
<head>
<title></title>
<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";
        }
        document.forms[0].appendChild(confirm_value);
    }
</script>
</head>
<body>
<form id="form1" runat="server">
  <asp:Button ID="btnConfirm" runat="server" 
 OnClick = "OnConfirm" Text ="Raise Confirm" OnClientClick = "Confirm()"/>
</form>
</body>
</html>

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);
}
else
{
    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
}
}

http://stackoverflow.com/questions/9833907/asp-net-confirm-before-executing-codebehind

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
                this.close();
            }
            else {
                return;
            }
        }
</script>

In the page load event

ClientScript.RegisterStartupScript(GetType(),"","ConfirmMessage()",true);

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,

Summer

Leave a Reply