Groups | Blog | Home
all groups > asp.net webcontrols > may 2004 >

asp.net webcontrols : Run validator when closing windows


Chris Leffer
5/29/2004 4:54:23 PM
I have a Requiredfieldvalidator on a page. If the user clicks my submit
button the validator works, but if the user closes the window the
validator does not work. How can I force the user to click my submit
button before he leaves my page?

Best regards,
Chris Leffer


*** Sent via Developersdex http://www.developersdex.com ***
Scott M.
5/30/2004 8:10:12 PM
Client side JavaScript:

<BODY onClose="theFormName.submit()">


[quoted text, click to view]

Robert Koritnik
6/1/2004 8:25:24 AM
Never seen a DHTML event onClose. If it really was that simple. Preventing
user from closing is a little bit more complicated than you can think.
Actually you can't prevent user from closing a window in the middle of some
important task, that you assume everyone will finish from start to end.
SOesn't work that way. Sorry.

First you'll have to connect some window events.


window.onblur = _toggleFocusMainWin;
window.onfocus = _toggleFocusMainWin;
document.body.onbeforeunload = _allowCloseMainWin;



function _toggleFocusMainWin()
{
if (window.event.type == 'blur')
window._isInFocus = false;
else
window._isInFocus = true;
}

// asks if the user really wants to close the main window
function _allowCloseMainWin()
{
if ((window._isInFocus) && (window.event.clientY < 0 ||
(window.event.altKey && _keyNumber == 115)))
window.event.returnValue = 'Press cancel, because your task is still
unfinished.';
}


Thisone checks for close click and Alt-F4... But this is not a super true
working script. A user could maybe click somewhere over the title bar. SO
the message can popup on some really strange click events. I'm just telling
you that preventing is impossible. You can just come close to it.

--
RobertK
{ Clever? No just smart. }

[quoted text, click to view]

AddThis Social Bookmark Button