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.
Asked
Active
Viewed 1,443 times
0
-
what sort of validation you need to perform on browser closed? – muhammad kashif Oct 17 '12 at 12:20
-
just capture the click event while closing the brower window. it will be a click event. so you can have : if(click event in browser window closes the window) alert("something"); – The Dark Knight Oct 17 '12 at 12:20
-
How to capture cross button on window? – F11 Oct 17 '12 at 12:30
-
There is a condition based on which i have to decide whether to show alert or not – F11 Oct 17 '12 at 12:31
3 Answers
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);
}
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