prompt before leaving page (ModalPopUp)

Hi,

I want to use a ModalPopUpExtender to prompt user that there is some unsaved data on page. It should works like 'onbeforeunload' function, but I want to use my own popup for a confirmation (ModalPopUpExtender). Please provide me with some sample code. Thanks a lot.

0
steensh
5/19/2008 11:46:01 AM
asp.net.client-side 24353 articles. 0 followers. Follow

4 Replies
2374 Views

Similar Articles

[PageSpeed] 24

there is some sample..

http://mattberseth.com/blog/2007/07/modalpopupextender_example_for.html

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ModalPopup/ModalPopup.aspx

i hope these help you


ihsany
######
Make It Easy
--------------dont forget to click <Mark As Answer>------------------
0
ihsany
5/19/2008 12:08:03 PM

I doubt very much that you can do that, as you would need to dig into browser functionality, which is really not possible. Always remember that you do not own the browser, the user does!

Here is how to do it with the built in browser method:
<script type="text/JavaScript">
<!--
window.onbeforeunload = function ()
{
 var closeMessage =
  'You are exiting this page.\n' +
  'If you have made changes without saving, your changes will be lost.\n' +
  'Are you sure you want to exit?';

 if ( window.event )
 {
  // IE only...

  window.event.returnValue = closeMessage;
 }
 else
 {
  // Other browsers NOTE: Never tested...
  return closeMessage;
 }
}
// -->
</script>

And here is how to prevent it from running if you happen to not want it to run under certain conditions.
     LinkButton1.Attributes.Add("onclick", "window.onbeforeunload = null;");

NC...

0
NC01
5/19/2008 12:44:00 PM

I've already known how to use AJAX ModalPopUp and 'onbeforeunload'. What I need is how to combine them.

My code:

window.onbeforeunload = function (e) 
{
if (typeof(postBack) != "undefined" && postBack == true)
return;
if(hasChanges())
{
document.getElementById('<%=btnConfirm.ClientID%>').click();

}
}

<asp:Button ID="btnConfirm" runat="server" Style="display: none" />

<asp:Panel ID="pnlConfirm" runat="server" Style="display: none">
<%--panel definition with 2 buttons: btnConfirmOK and btnConfirmCancel --%> </asp:Panel>

<mpe:ModalPopupExtender ID="mpeConfirm" runat="server" OkControlID="btnConfirmOK" CancelControlID="btnConfirmCancel" PopupControlID="pnlConfirm" TargetControlID="btnConfirm">
</mpe:ModalPopupExtender>

 
hasChanges() obviously check if there was modification on page. btnConfirmOK and btnConfirmCancel should act like default JavaScript OK and Cancel button in default JavaScript pupup.

I think there should be 3 steps:

1. remeber user clicked redirection page 

2. display modalpopup

3. redirect user to clicked page if he chose not to save data 

Am I thinking correct? Please help me with this.

0
steensh
5/19/2008 1:03:51 PM

steensh:

I've already known how to use AJAX ModalPopUp and 'onbeforeunload'. What I need is how to combine them.

My code:

window.onbeforeunload = function (e) 
{
if (typeof(postBack) != "undefined" && postBack == true)
return;
if(hasChanges())
{
document.getElementById('<%=btnConfirm.ClientID%>').click();

}
}

<asp:Button ID="btnConfirm" runat="server" Style="display: none" />

<asp:Panel ID="pnlConfirm" runat="server" Style="display: none">
<%--panel definition with 2 buttons: btnConfirmOK and btnConfirmCancel --%> </asp:Panel>

<mpe:ModalPopupExtender ID="mpeConfirm" runat="server" OkControlID="btnConfirmOK" CancelControlID="btnConfirmCancel" PopupControlID="pnlConfirm" TargetControlID="btnConfirm">
</mpe:ModalPopupExtender>


hasChanges() obviously check if there was modification on page. btnConfirmOK and btnConfirmCancel should act like default JavaScript OK and Cancel button in default JavaScript pupup.

I think there should be 3 steps:

1. remeber user clicked redirection page 

2. display modalpopup

3. redirect user to clicked page if he chose not to save data 

Am I thinking correct? Please help me with this.

I doubt if that will work for the reasons that I stated in my previous post.

NC...

 

0
NC01
5/19/2008 1:13:14 PM
Reply:

Similar Artilces:

UserControl and ModalPopUp prompt when user leaves page
 Hi,I have some UserControl which is used in many pages in my application. I want to prompt user (by ModalPopUp) that there is an unsaved data in a control. This prompt should be when user leaves page and there is an unsaved data in my UserControl.Please help me with this issue.  <body onLoad="closing=true" onUnload="if (closing) alert('you are closing window');"> check for the values in your use control in unload event and call a prompt  window to save or cancelAbipeter When user change something in data, that time you can set the flag or...

Client Side Events In HTML Page with .NET VB Class
Hi Im new to .NET so please excuse me. Ive been scratching my head for a week now trying to convert some code from VB6 to .NET I have currently this code in HTML <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>Default</title> <META content="VBScript" name="vs_defaultClientScript"> <META content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> <META content="Microsoft Visual Studio.NET 7.0" name=...

server side or client side page?
a page that contain a validation control and starting a storeProcedures when the user click on a button --is considered as a client side page or as a server side page?it seems to me that in asp.net everthing is server side, where are the client side pages?thanks The sp is server side, but the validation can be on or the other, depending on how it's coded.ASP.Net has it's validations, so it's server side when using them.But you can also make validations via JavaScript, so that would be client side.Zath but the validation controls (like RequiredFiledValidator) is a client side va...

XMLHTTP in .Net
I'm trying to convert an ASP page that uses XMLHTTP. At first I removed the XMLHTTP code and used regular server side code. Now I'm finding the XMLHTTP code (or something like it) might be needed. The situation is that the page has a lot of data on it in text boxes and drop down lists and response is very slow each time we send data back and forth to the server. On the ASP page the XMLHTTP was used to limit the trips to the server and the amount of data sent back and forth. It was used in client side code to do things like populate a drop down list when the value in a different drop down ...

how to get value from client side script Prompt window to a session var in .net
hi guyz, i hav a problem with getting a value from a client-side inputbox to a session var in .net. is this possible? however, when i click submit button this is the code that's triggered. dim sb as New System.Text.StringBuilder sb.append("<script language=" & """" & "vbscript" & """" & ">") sb.append(vbcrlf) sb.append(vbcrlf) sb.append("do while xLate =" & """" & """") sb.append(vbcrlf) '//prompt window, val...

How can i create get values from Opened page in client side to my first page(server page)
i have a little bit problem that my Server page has coding like this : btn.attributes.add("onclick()",getdata()) and one text box is txt1 now when user clicks it Button btn then getdata function  executes ok client page function getdata(){ response.redirect("hello.aspx") } now on hello.aspx has 1 textbox txt2   now what ever the data has been inputted by user in (client side textbox) txt2 i want to assign it to txt1 (server side )conrtol on server pls help me send me code ...  Jay "Enjoy Life" When you do the redirect from Page #2 back to Page...

Jscript, moving from client-side to server-side (.NET)
Hey all I’m working translating a web-app written in client-side Jscript to run on the server-side as JScript.NET. Without needing to get too specific, I am using Jscript because the original page aggregated raw data to produce statistical results (this was done dynamically based on user 'sort-by' options). The final output is an html report that can be emailed. Because this is currently being done on the client side, as the raw data grows the load-time grows as well (to the point that has almost become unusable). I’m posting here to see if anyone has any experi...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in asp.net ( required field, range validator and others)..my question is the required field validator is a server side control. So does that mean that it does a post back?..is it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

When to use client side varidation and server side varidation in .net?
In .net or classic web application we can varidate user data either on client isde or server side. How to select which side varidate to be used? Thanks! Generally, I use both client and server validation. I make sure the input is in the correct format and reasonably valid on the client, then I verify the data on the server. The extent of validation also depends on the type of data that I need to validate.Here are a few references:Validating ASP.NET Server ControlsIntroduction to Validating User Input in Web FormsClient-Side Validation for ASP.NET Server ControlsSecurity Checklist...

communication between client side(java script) and server side in .net project
I have a question which is, when building a .net project, we are able to use server side code and client side code(java script). How do they communicate? Thanks Client Side coding works with the WebBrowser. So when ever you write client side code you have to keep browser compatability in your mind and you have to code. Server Side code works with Web Server (IIS) and it's ASPNET ISAPI's. The won't directly communicate with each other. But using AJAX you can all server side code from Client Side! Example article on Ajax@ http://www.devarticles.com/index2.php?option=content&task=...

Call server-side page function from client-side button click
I have an existing ASP application that I am migrating to ASP.net. In the ASP app I was using the Microsoft.XMLHTTP on a the client-side of a ASP page to retrieve data from another asp page using the Microsoft.XMLDOM object. The client page passes 3 tags columns, table and Criteria. The receiving page builds the SQL statement executes the query and returns the row with all the column data. I am trying to convert it over to ASP.NET and I am getting errors on the xmlDOM.Load(Request.InputStream) on DLookup.aspx, the code is listed below. Someone suggested to use System.Net HTTP classes su...

Client side page
Hello, my readers. This is my today's problem. I create a client side page. In this page I would like to insert a DIV object with a style='position:relative; width:100%; height:100%;' Moreover, I would like some actions to be triggered during OnLoad and OnResize events of the Page's body.For this reason I have to include in the client page all the scripts (one external on another server, one directly on the page) and the CSS styles I need. Moreover, I would like some actions to be triggered during OnLoad and OnResize events of the Page's body. For this reason I have t...

Accessing server-side control in client-side javascript function; on Content page
I am trying to set an asp:textbox value in the Client side javascript function. It works fine on the standalone page. But when i try to do this the Content page, it’s giving the follwoing error message. document.getElementByID[...] is null of not an object  Any idea? Thanks, Riz   Hi, are you using ClientID property of that server control, to get its ID (which is rendered at the client and can be used with document.getElementById )?Thanks,Teemu KeiskiFinland, EU Thank you my problem is solved....

how to do paging on client side
how can i do paging on client side in datagrid in asp .neti have done paging but it post back to server ,how can i make paging on client side There is no built-in featrue to do that, you will have to write some javascrit code. One way of doing this would be implementing ItemDataBound (or looping through the Items collection of the datagrid once it has been databound) and hiding the items outside of the 1st page plus creating an array containing the IDs of the table rows. Then you'll write a javascript that will hide all the items in a grid but those corresponding to the page number ...

Web resources about - prompt before leaving page (ModalPopUp) - asp.net.client-side

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

BubbleChart Sample
Samples HOME Accordion AjaxFileUpload AlwaysVisibleControl Animation AreaChart AsyncFileUpload AutoComplete BalloonPopup BarChart BubbleChart ...

AreaChart Sample
Samples HOME Accordion AjaxFileUpload AlwaysVisibleControl Animation AreaChart AsyncFileUpload AutoComplete BalloonPopup BarChart BubbleChart ...

ModalPopup Sample
ASP.NET AJAX is a free framework for building a new generation of richer, more interactive, highly personalized cross-browser web applications. ...

LineChart Sample
Samples HOME Accordion AjaxFileUpload AlwaysVisibleControl Animation AreaChart AsyncFileUpload AutoComplete BalloonPopup BarChart BubbleChart ...

AsyncFileUpload Sample
Samples HOME Accordion AjaxFileUpload AlwaysVisibleControl Animation AreaChart AsyncFileUpload AutoComplete BalloonPopup BarChart BubbleChart ...

DropDown Sample
Samples HOME Accordion AjaxFileUpload AlwaysVisibleControl Animation AreaChart AsyncFileUpload AutoComplete BalloonPopup BarChart BubbleChart ...

Ajax Control Toolkit Tutorials - ASP.NET Ajax Library
ASP.NET Home Get Started Learn WEB APPLICATIONS Web Forms MVC Web Pages/Razor Mobile Single Page Apps Common ASP.NET Features WEB SERVICES / ...

ListSearch Sample
Samples HOME Accordion AjaxFileUpload AlwaysVisibleControl Animation AreaChart AsyncFileUpload AutoComplete BalloonPopup BarChart BubbleChart ...

Resources last updated: 1/8/2016 10:45:15 AM