0

I have to show alert on my web page after some server side validation(Based on certain condition to whether display alert or not) when browser cross is clicked and after the alert message the page should not be closed. I do everything from Codebehind. No single line of code in aspx page. Can anybody provide code snippet. I am using .net1.1.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
F11
  • 3,703
  • 12
  • 49
  • 83

3 Answers3

1

Use the below code..

ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('sucessfully saved');",true);

Kamal Deepak
  • 221
  • 1
  • 3
  • 9
0

Just add some Javascript to the page when you do the validation in CodeBehind.

Here´s described how to show a popup with JavaScript when the tab is closed. To add plain text (JavaScript in our case) to your HTML, you can use a LiteralControl.

Some Code:

        if (warningNecessary)
        {
            LiteralControl lc = new LiteralControl();
            lc.Text = string.Concat("<script type=\"text/javascript\">",
                                        "window.onUnLoad= function (evt) {",
                                        "alert('YourAlert');",
                                        "}",
                                    "</script>");
            this.Controls.Add(lc);
        }   
Community
  • 1
  • 1
Mx.
  • 3,588
  • 2
  • 25
  • 33
0

When I close the browser,i have to perofrm some server side functions.

if any exception comes in these server side function,i have to show an alert message that "Operation Unsuccessful" and in that case browser should not be closed.

else close the browser.

F11
  • 3,703
  • 12
  • 49
  • 83