Connecting Tech Pros Worldwide Forums | Help | Site Map

IsFormDirty

Stanley
Guest
 
Posts: n/a
#1: Nov 18 '05
Hello all,
I have a need to make sure that no users leave a form without being warned
that they have un-saved data. I have the script below that I found on
egghead.com but there is an issue with it that if I have a dropdown that
posts back so that I can show another field if the user chooses other then
the warning pops up. If I use an attribute on the dropdown to use the
OnChange event and set the bSubmitted=True that takes care of the post back
issue but causes another issue. The other issue is now the user can leave
the form without any warning. So what I am looking for is a better way to be
able to handle form post backs and still give the user the warning. Has
anyone done this before?

TIA

-Stanley

[script]
var bSubmitted=false;

function isDirty(oForm)

{

if(bSubmitted)

{

return false;

}

var iNumElems = oForm.elements.length;

for (var i=0;i<iNumElems;i++)

{

var oElem = oForm.elements[i];

if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)

{

if (oElem.value != oElem.defaultValue)

{

return true;

}

}

else if ("checkbox" == oElem.type || "radio" == oElem.type)

{

if (oElem.checked != oElem.defaultChecked)

{

return true;

}

}

else if ("SELECT" == oElem.tagName)

{

var oOptions = oElem.options;

var iNumOpts = oOptions.length;

for (var j=0;j<iNumOpts;j++)

{

var oOpt = oOptions[j];

if (oOpt.selected != oOpt.defaultSelected)

{

return true;

}

}

}

}

return false;

}

function checkFormStatus(){

var frm = document.forms[0];

if(isDirty(frm))

event.returnValue = "You have entered form Data, or Data has been entered
for you, without submitting this form.";

}

if ( typeof( window.addEventListener ) != "undefined" ) {

window.addEventListener("onbeforeunload", checkFormStatus, false);

} else if ( typeof( window.attachEvent ) != "undefined" ) {

window.attachEvent("onbeforeunload", checkFormStatus);

}

[/script]



Alvin Bruney [MVP]
Guest
 
Posts: n/a
#2: Nov 18 '05

re: IsFormDirty


Your post went unanswered. Have you resolved this issue?

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Stanley" <webmaster@nospam-glass-images.com> wrote in message
news:eHB%23i5IAEHA.2040@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hello all,
> I have a need to make sure that no users leave a form without being warned
> that they have un-saved data. I have the script below that I found on
> egghead.com but there is an issue with it that if I have a dropdown that
> posts back so that I can show another field if the user chooses other then
> the warning pops up. If I use an attribute on the dropdown to use the
> OnChange event and set the bSubmitted=True that takes care of the post[/color]
back[color=blue]
> issue but causes another issue. The other issue is now the user can leave
> the form without any warning. So what I am looking for is a better way to[/color]
be[color=blue]
> able to handle form post backs and still give the user the warning. Has
> anyone done this before?
>
> TIA
>
> -Stanley
>
> [script]
> var bSubmitted=false;
>
> function isDirty(oForm)
>
> {
>
> if(bSubmitted)
>
> {
>
> return false;
>
> }
>
> var iNumElems = oForm.elements.length;
>
> for (var i=0;i<iNumElems;i++)
>
> {
>
> var oElem = oForm.elements[i];
>
> if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
>
> {
>
> if (oElem.value != oElem.defaultValue)
>
> {
>
> return true;
>
> }
>
> }
>
> else if ("checkbox" == oElem.type || "radio" == oElem.type)
>
> {
>
> if (oElem.checked != oElem.defaultChecked)
>
> {
>
> return true;
>
> }
>
> }
>
> else if ("SELECT" == oElem.tagName)
>
> {
>
> var oOptions = oElem.options;
>
> var iNumOpts = oOptions.length;
>
> for (var j=0;j<iNumOpts;j++)
>
> {
>
> var oOpt = oOptions[j];
>
> if (oOpt.selected != oOpt.defaultSelected)
>
> {
>
> return true;
>
> }
>
> }
>
> }
>
> }
>
> return false;
>
> }
>
> function checkFormStatus(){
>
> var frm = document.forms[0];
>
> if(isDirty(frm))
>
> event.returnValue = "You have entered form Data, or Data has been entered
> for you, without submitting this form.";
>
> }
>
> if ( typeof( window.addEventListener ) != "undefined" ) {
>
> window.addEventListener("onbeforeunload", checkFormStatus, false);
>
> } else if ( typeof( window.attachEvent ) != "undefined" ) {
>
> window.attachEvent("onbeforeunload", checkFormStatus);
>
> }
>
> [/script]
>
>[/color]


Stanley
Guest
 
Posts: n/a
#3: Nov 18 '05

re: IsFormDirty


No I have not resolved this issue yet.

-Stanley

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:%23WlnPaZAEHA.2316@TK2MSFTNGP10.phx.gbl...[color=blue]
> Your post went unanswered. Have you resolved this issue?
>
> --
> Regards,
> Alvin Bruney [ASP.NET MVP]
> Got tidbits? Get it here...
> http://tinyurl.com/3he3b
> "Stanley" <webmaster@nospam-glass-images.com> wrote in message
> news:eHB%23i5IAEHA.2040@TK2MSFTNGP12.phx.gbl...[color=green]
> > Hello all,
> > I have a need to make sure that no users leave a form without being[/color][/color]
warned[color=blue][color=green]
> > that they have un-saved data. I have the script below that I found on
> > egghead.com but there is an issue with it that if I have a dropdown that
> > posts back so that I can show another field if the user chooses other[/color][/color]
then[color=blue][color=green]
> > the warning pops up. If I use an attribute on the dropdown to use the
> > OnChange event and set the bSubmitted=True that takes care of the post[/color]
> back[color=green]
> > issue but causes another issue. The other issue is now the user can[/color][/color]
leave[color=blue][color=green]
> > the form without any warning. So what I am looking for is a better way[/color][/color]
to[color=blue]
> be[color=green]
> > able to handle form post backs and still give the user the warning. Has
> > anyone done this before?
> >
> > TIA
> >
> > -Stanley
> >
> > [script]
> > var bSubmitted=false;
> >
> > function isDirty(oForm)
> >
> > {
> >
> > if(bSubmitted)
> >
> > {
> >
> > return false;
> >
> > }
> >
> > var iNumElems = oForm.elements.length;
> >
> > for (var i=0;i<iNumElems;i++)
> >
> > {
> >
> > var oElem = oForm.elements[i];
> >
> > if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
> >
> > {
> >
> > if (oElem.value != oElem.defaultValue)
> >
> > {
> >
> > return true;
> >
> > }
> >
> > }
> >
> > else if ("checkbox" == oElem.type || "radio" == oElem.type)
> >
> > {
> >
> > if (oElem.checked != oElem.defaultChecked)
> >
> > {
> >
> > return true;
> >
> > }
> >
> > }
> >
> > else if ("SELECT" == oElem.tagName)
> >
> > {
> >
> > var oOptions = oElem.options;
> >
> > var iNumOpts = oOptions.length;
> >
> > for (var j=0;j<iNumOpts;j++)
> >
> > {
> >
> > var oOpt = oOptions[j];
> >
> > if (oOpt.selected != oOpt.defaultSelected)
> >
> > {
> >
> > return true;
> >
> > }
> >
> > }
> >
> > }
> >
> > }
> >
> > return false;
> >
> > }
> >
> > function checkFormStatus(){
> >
> > var frm = document.forms[0];
> >
> > if(isDirty(frm))
> >
> > event.returnValue = "You have entered form Data, or Data has been[/color][/color]
entered[color=blue][color=green]
> > for you, without submitting this form.";
> >
> > }
> >
> > if ( typeof( window.addEventListener ) != "undefined" ) {
> >
> > window.addEventListener("onbeforeunload", checkFormStatus, false);
> >
> > } else if ( typeof( window.attachEvent ) != "undefined" ) {
> >
> > window.attachEvent("onbeforeunload", checkFormStatus);
> >
> > }
> >
> > [/script]
> >
> >[/color]
>
>[/color]


Alvin Bruney [MVP]
Guest
 
Posts: n/a
#4: Nov 18 '05

re: IsFormDirty


What i think you need, if i understand you correctly, is a validation
control in there. The role of a validation control is to make sure that the
user has entered input before they move on. Have a look at the visual studio
toolbox for the appropriate validation control

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Stanley" <webmaster@nospam-glass-images.com> wrote in message
news:%23so6tSeAEHA.3220@TK2MSFTNGP10.phx.gbl...[color=blue]
> No I have not resolved this issue yet.
>
> -Stanley
>
> "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> news:%23WlnPaZAEHA.2316@TK2MSFTNGP10.phx.gbl...[color=green]
> > Your post went unanswered. Have you resolved this issue?
> >
> > --
> > Regards,
> > Alvin Bruney [ASP.NET MVP]
> > Got tidbits? Get it here...
> > http://tinyurl.com/3he3b
> > "Stanley" <webmaster@nospam-glass-images.com> wrote in message
> > news:eHB%23i5IAEHA.2040@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > Hello all,
> > > I have a need to make sure that no users leave a form without being[/color][/color]
> warned[color=green][color=darkred]
> > > that they have un-saved data. I have the script below that I found on
> > > egghead.com but there is an issue with it that if I have a dropdown[/color][/color][/color]
that[color=blue][color=green][color=darkred]
> > > posts back so that I can show another field if the user chooses other[/color][/color]
> then[color=green][color=darkred]
> > > the warning pops up. If I use an attribute on the dropdown to use the
> > > OnChange event and set the bSubmitted=True that takes care of the post[/color]
> > back[color=darkred]
> > > issue but causes another issue. The other issue is now the user can[/color][/color]
> leave[color=green][color=darkred]
> > > the form without any warning. So what I am looking for is a better way[/color][/color]
> to[color=green]
> > be[color=darkred]
> > > able to handle form post backs and still give the user the warning.[/color][/color][/color]
Has[color=blue][color=green][color=darkred]
> > > anyone done this before?
> > >
> > > TIA
> > >
> > > -Stanley
> > >
> > > [script]
> > > var bSubmitted=false;
> > >
> > > function isDirty(oForm)
> > >
> > > {
> > >
> > > if(bSubmitted)
> > >
> > > {
> > >
> > > return false;
> > >
> > > }
> > >
> > > var iNumElems = oForm.elements.length;
> > >
> > > for (var i=0;i<iNumElems;i++)
> > >
> > > {
> > >
> > > var oElem = oForm.elements[i];
> > >
> > > if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
> > >
> > > {
> > >
> > > if (oElem.value != oElem.defaultValue)
> > >
> > > {
> > >
> > > return true;
> > >
> > > }
> > >
> > > }
> > >
> > > else if ("checkbox" == oElem.type || "radio" == oElem.type)
> > >
> > > {
> > >
> > > if (oElem.checked != oElem.defaultChecked)
> > >
> > > {
> > >
> > > return true;
> > >
> > > }
> > >
> > > }
> > >
> > > else if ("SELECT" == oElem.tagName)
> > >
> > > {
> > >
> > > var oOptions = oElem.options;
> > >
> > > var iNumOpts = oOptions.length;
> > >
> > > for (var j=0;j<iNumOpts;j++)
> > >
> > > {
> > >
> > > var oOpt = oOptions[j];
> > >
> > > if (oOpt.selected != oOpt.defaultSelected)
> > >
> > > {
> > >
> > > return true;
> > >
> > > }
> > >
> > > }
> > >
> > > }
> > >
> > > }
> > >
> > > return false;
> > >
> > > }
> > >
> > > function checkFormStatus(){
> > >
> > > var frm = document.forms[0];
> > >
> > > if(isDirty(frm))
> > >
> > > event.returnValue = "You have entered form Data, or Data has been[/color][/color]
> entered[color=green][color=darkred]
> > > for you, without submitting this form.";
> > >
> > > }
> > >
> > > if ( typeof( window.addEventListener ) != "undefined" ) {
> > >
> > > window.addEventListener("onbeforeunload", checkFormStatus, false);
> > >
> > > } else if ( typeof( window.attachEvent ) != "undefined" ) {
> > >
> > > window.attachEvent("onbeforeunload", checkFormStatus);
> > >
> > > }
> > >
> > > [/script]
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Eric
Guest
 
Posts: n/a
#5: Nov 18 '05

re: IsFormDirty


See http://www.codeproject.com/aspnet/EWSWebPt2.asp for one possible
solution.


"Stanley" <webmaster@nospam-glass-images.com> wrote in message
news:eHB%23i5IAEHA.2040@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hello all,
> I have a need to make sure that no users leave a form without being warned
> that they have un-saved data. I have the script below that I found on
> egghead.com but there is an issue with it that if I have a dropdown that
> posts back so that I can show another field if the user chooses other then
> the warning pops up. If I use an attribute on the dropdown to use the
> OnChange event and set the bSubmitted=True that takes care of the post[/color]
back[color=blue]
> issue but causes another issue. The other issue is now the user can leave
> the form without any warning. So what I am looking for is a better way to[/color]
be[color=blue]
> able to handle form post backs and still give the user the warning. Has
> anyone done this before?
>
> TIA
>
> -Stanley
>
> [script]
> var bSubmitted=false;
>
> function isDirty(oForm)
>
> {
>
> if(bSubmitted)
>
> {
>
> return false;
>
> }
>
> var iNumElems = oForm.elements.length;
>
> for (var i=0;i<iNumElems;i++)
>
> {
>
> var oElem = oForm.elements[i];
>
> if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
>
> {
>
> if (oElem.value != oElem.defaultValue)
>
> {
>
> return true;
>
> }
>
> }
>
> else if ("checkbox" == oElem.type || "radio" == oElem.type)
>
> {
>
> if (oElem.checked != oElem.defaultChecked)
>
> {
>
> return true;
>
> }
>
> }
>
> else if ("SELECT" == oElem.tagName)
>
> {
>
> var oOptions = oElem.options;
>
> var iNumOpts = oOptions.length;
>
> for (var j=0;j<iNumOpts;j++)
>
> {
>
> var oOpt = oOptions[j];
>
> if (oOpt.selected != oOpt.defaultSelected)
>
> {
>
> return true;
>
> }
>
> }
>
> }
>
> }
>
> return false;
>
> }
>
> function checkFormStatus(){
>
> var frm = document.forms[0];
>
> if(isDirty(frm))
>
> event.returnValue = "You have entered form Data, or Data has been entered
> for you, without submitting this form.";
>
> }
>
> if ( typeof( window.addEventListener ) != "undefined" ) {
>
> window.addEventListener("onbeforeunload", checkFormStatus, false);
>
> } else if ( typeof( window.attachEvent ) != "undefined" ) {
>
> window.attachEvent("onbeforeunload", checkFormStatus);
>
> }
>
> [/script]
>
>[/color]


Stanley
Guest
 
Posts: n/a
#6: Nov 18 '05

re: IsFormDirty


I tried that solution and it has the same problem as my code. If I have
autopostback on a dropdown then the user can go away from the page.

-Stanley

"Eric" <MagikNozeGoblin@HotMail.com> wrote in message
news:e9lnc3lAEHA.2216@TK2MSFTNGP10.phx.gbl...[color=blue]
> See http://www.codeproject.com/aspnet/EWSWebPt2.asp for one possible
> solution.
>
>
> "Stanley" <webmaster@nospam-glass-images.com> wrote in message
> news:eHB%23i5IAEHA.2040@TK2MSFTNGP12.phx.gbl...[color=green]
> > Hello all,
> > I have a need to make sure that no users leave a form without being[/color][/color]
warned[color=blue][color=green]
> > that they have un-saved data. I have the script below that I found on
> > egghead.com but there is an issue with it that if I have a dropdown that
> > posts back so that I can show another field if the user chooses other[/color][/color]
then[color=blue][color=green]
> > the warning pops up. If I use an attribute on the dropdown to use the
> > OnChange event and set the bSubmitted=True that takes care of the post[/color]
> back[color=green]
> > issue but causes another issue. The other issue is now the user can[/color][/color]
leave[color=blue][color=green]
> > the form without any warning. So what I am looking for is a better way[/color][/color]
to[color=blue]
> be[color=green]
> > able to handle form post backs and still give the user the warning. Has
> > anyone done this before?
> >
> > TIA
> >
> > -Stanley
> >
> > [script]
> > var bSubmitted=false;
> >
> > function isDirty(oForm)
> >
> > {
> >
> > if(bSubmitted)
> >
> > {
> >
> > return false;
> >
> > }
> >
> > var iNumElems = oForm.elements.length;
> >
> > for (var i=0;i<iNumElems;i++)
> >
> > {
> >
> > var oElem = oForm.elements[i];
> >
> > if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
> >
> > {
> >
> > if (oElem.value != oElem.defaultValue)
> >
> > {
> >
> > return true;
> >
> > }
> >
> > }
> >
> > else if ("checkbox" == oElem.type || "radio" == oElem.type)
> >
> > {
> >
> > if (oElem.checked != oElem.defaultChecked)
> >
> > {
> >
> > return true;
> >
> > }
> >
> > }
> >
> > else if ("SELECT" == oElem.tagName)
> >
> > {
> >
> > var oOptions = oElem.options;
> >
> > var iNumOpts = oOptions.length;
> >
> > for (var j=0;j<iNumOpts;j++)
> >
> > {
> >
> > var oOpt = oOptions[j];
> >
> > if (oOpt.selected != oOpt.defaultSelected)
> >
> > {
> >
> > return true;
> >
> > }
> >
> > }
> >
> > }
> >
> > }
> >
> > return false;
> >
> > }
> >
> > function checkFormStatus(){
> >
> > var frm = document.forms[0];
> >
> > if(isDirty(frm))
> >
> > event.returnValue = "You have entered form Data, or Data has been[/color][/color]
entered[color=blue][color=green]
> > for you, without submitting this form.";
> >
> > }
> >
> > if ( typeof( window.addEventListener ) != "undefined" ) {
> >
> > window.addEventListener("onbeforeunload", checkFormStatus, false);
> >
> > } else if ( typeof( window.attachEvent ) != "undefined" ) {
> >
> > window.attachEvent("onbeforeunload", checkFormStatus);
> >
> > }
> >
> > [/script]
> >
> >[/color]
>
>[/color]


Stanley
Guest
 
Posts: n/a
#7: Nov 18 '05

re: IsFormDirty


Actually no Alvin a Validator wont work for what I need. If the user clicks
a link to go to another page that is listed on my menu a validator won't
stop them from going. That was the request made by my boss.

-Stanley

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:uPmL68kAEHA.2480@TK2MSFTNGP11.phx.gbl...[color=blue]
> What i think you need, if i understand you correctly, is a validation
> control in there. The role of a validation control is to make sure that[/color]
the[color=blue]
> user has entered input before they move on. Have a look at the visual[/color]
studio[color=blue]
> toolbox for the appropriate validation control
>
> --
> Regards,
> Alvin Bruney [ASP.NET MVP]
> Got tidbits? Get it here...
> http://tinyurl.com/3he3b
> "Stanley" <webmaster@nospam-glass-images.com> wrote in message
> news:%23so6tSeAEHA.3220@TK2MSFTNGP10.phx.gbl...[color=green]
> > No I have not resolved this issue yet.
> >
> > -Stanley
> >
> > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> > news:%23WlnPaZAEHA.2316@TK2MSFTNGP10.phx.gbl...[color=darkred]
> > > Your post went unanswered. Have you resolved this issue?
> > >
> > > --
> > > Regards,
> > > Alvin Bruney [ASP.NET MVP]
> > > Got tidbits? Get it here...
> > > http://tinyurl.com/3he3b
> > > "Stanley" <webmaster@nospam-glass-images.com> wrote in message
> > > news:eHB%23i5IAEHA.2040@TK2MSFTNGP12.phx.gbl...
> > > > Hello all,
> > > > I have a need to make sure that no users leave a form without being[/color]
> > warned[color=darkred]
> > > > that they have un-saved data. I have the script below that I found[/color][/color][/color]
on[color=blue][color=green][color=darkred]
> > > > egghead.com but there is an issue with it that if I have a dropdown[/color][/color]
> that[color=green][color=darkred]
> > > > posts back so that I can show another field if the user chooses[/color][/color][/color]
other[color=blue][color=green]
> > then[color=darkred]
> > > > the warning pops up. If I use an attribute on the dropdown to use[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > > OnChange event and set the bSubmitted=True that takes care of the[/color][/color][/color]
post[color=blue][color=green][color=darkred]
> > > back
> > > > issue but causes another issue. The other issue is now the user can[/color]
> > leave[color=darkred]
> > > > the form without any warning. So what I am looking for is a better[/color][/color][/color]
way[color=blue][color=green]
> > to[color=darkred]
> > > be
> > > > able to handle form post backs and still give the user the warning.[/color][/color]
> Has[color=green][color=darkred]
> > > > anyone done this before?
> > > >
> > > > TIA
> > > >
> > > > -Stanley
> > > >
> > > > [script]
> > > > var bSubmitted=false;
> > > >
> > > > function isDirty(oForm)
> > > >
> > > > {
> > > >
> > > > if(bSubmitted)
> > > >
> > > > {
> > > >
> > > > return false;
> > > >
> > > > }
> > > >
> > > > var iNumElems = oForm.elements.length;
> > > >
> > > > for (var i=0;i<iNumElems;i++)
> > > >
> > > > {
> > > >
> > > > var oElem = oForm.elements[i];
> > > >
> > > > if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
> > > >
> > > > {
> > > >
> > > > if (oElem.value != oElem.defaultValue)
> > > >
> > > > {
> > > >
> > > > return true;
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > > else if ("checkbox" == oElem.type || "radio" == oElem.type)
> > > >
> > > > {
> > > >
> > > > if (oElem.checked != oElem.defaultChecked)
> > > >
> > > > {
> > > >
> > > > return true;
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > > else if ("SELECT" == oElem.tagName)
> > > >
> > > > {
> > > >
> > > > var oOptions = oElem.options;
> > > >
> > > > var iNumOpts = oOptions.length;
> > > >
> > > > for (var j=0;j<iNumOpts;j++)
> > > >
> > > > {
> > > >
> > > > var oOpt = oOptions[j];
> > > >
> > > > if (oOpt.selected != oOpt.defaultSelected)
> > > >
> > > > {
> > > >
> > > > return true;
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > > return false;
> > > >
> > > > }
> > > >
> > > > function checkFormStatus(){
> > > >
> > > > var frm = document.forms[0];
> > > >
> > > > if(isDirty(frm))
> > > >
> > > > event.returnValue = "You have entered form Data, or Data has been[/color]
> > entered[color=darkred]
> > > > for you, without submitting this form.";
> > > >
> > > > }
> > > >
> > > > if ( typeof( window.addEventListener ) != "undefined" ) {
> > > >
> > > > window.addEventListener("onbeforeunload", checkFormStatus, false);
> > > >
> > > > } else if ( typeof( window.attachEvent ) != "undefined" ) {
> > > >
> > > > window.attachEvent("onbeforeunload", checkFormStatus);
> > > >
> > > > }
> > > >
> > > > [/script]
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Alvin Bruney [MVP]
Guest
 
Posts: n/a
#8: Nov 18 '05

re: IsFormDirty


Every postback causes page_load to fire. Put code in your page load to
determine whether or not the action should be allowed. If it's not a
postback, you can easily handle it thru scripting or validation.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Stanley" <webmaster@nospam-glass-images.com> wrote in message
news:%23Fad%23ntAEHA.4080@TK2MSFTNGP09.phx.gbl...[color=blue]
> Actually no Alvin a Validator wont work for what I need. If the user[/color]
clicks[color=blue]
> a link to go to another page that is listed on my menu a validator won't
> stop them from going. That was the request made by my boss.
>
> -Stanley
>
> "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> news:uPmL68kAEHA.2480@TK2MSFTNGP11.phx.gbl...[color=green]
> > What i think you need, if i understand you correctly, is a validation
> > control in there. The role of a validation control is to make sure that[/color]
> the[color=green]
> > user has entered input before they move on. Have a look at the visual[/color]
> studio[color=green]
> > toolbox for the appropriate validation control
> >
> > --
> > Regards,
> > Alvin Bruney [ASP.NET MVP]
> > Got tidbits? Get it here...
> > http://tinyurl.com/3he3b
> > "Stanley" <webmaster@nospam-glass-images.com> wrote in message
> > news:%23so6tSeAEHA.3220@TK2MSFTNGP10.phx.gbl...[color=darkred]
> > > No I have not resolved this issue yet.
> > >
> > > -Stanley
> > >
> > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> > > news:%23WlnPaZAEHA.2316@TK2MSFTNGP10.phx.gbl...
> > > > Your post went unanswered. Have you resolved this issue?
> > > >
> > > > --
> > > > Regards,
> > > > Alvin Bruney [ASP.NET MVP]
> > > > Got tidbits? Get it here...
> > > > http://tinyurl.com/3he3b
> > > > "Stanley" <webmaster@nospam-glass-images.com> wrote in message
> > > > news:eHB%23i5IAEHA.2040@TK2MSFTNGP12.phx.gbl...
> > > > > Hello all,
> > > > > I have a need to make sure that no users leave a form without[/color][/color][/color]
being[color=blue][color=green][color=darkred]
> > > warned
> > > > > that they have un-saved data. I have the script below that I found[/color][/color]
> on[color=green][color=darkred]
> > > > > egghead.com but there is an issue with it that if I have a[/color][/color][/color]
dropdown[color=blue][color=green]
> > that[color=darkred]
> > > > > posts back so that I can show another field if the user chooses[/color][/color]
> other[color=green][color=darkred]
> > > then
> > > > > the warning pops up. If I use an attribute on the dropdown to use[/color][/color]
> the[color=green][color=darkred]
> > > > > OnChange event and set the bSubmitted=True that takes care of the[/color][/color]
> post[color=green][color=darkred]
> > > > back
> > > > > issue but causes another issue. The other issue is now the user[/color][/color][/color]
can[color=blue][color=green][color=darkred]
> > > leave
> > > > > the form without any warning. So what I am looking for is a better[/color][/color]
> way[color=green][color=darkred]
> > > to
> > > > be
> > > > > able to handle form post backs and still give the user the[/color][/color][/color]
warning.[color=blue][color=green]
> > Has[color=darkred]
> > > > > anyone done this before?
> > > > >
> > > > > TIA
> > > > >
> > > > > -Stanley
> > > > >
> > > > > [script]
> > > > > var bSubmitted=false;
> > > > >
> > > > > function isDirty(oForm)
> > > > >
> > > > > {
> > > > >
> > > > > if(bSubmitted)
> > > > >
> > > > > {
> > > > >
> > > > > return false;
> > > > >
> > > > > }
> > > > >
> > > > > var iNumElems = oForm.elements.length;
> > > > >
> > > > > for (var i=0;i<iNumElems;i++)
> > > > >
> > > > > {
> > > > >
> > > > > var oElem = oForm.elements[i];
> > > > >
> > > > > if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
> > > > >
> > > > > {
> > > > >
> > > > > if (oElem.value != oElem.defaultValue)
> > > > >
> > > > > {
> > > > >
> > > > > return true;
> > > > >
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > > else if ("checkbox" == oElem.type || "radio" == oElem.type)
> > > > >
> > > > > {
> > > > >
> > > > > if (oElem.checked != oElem.defaultChecked)
> > > > >
> > > > > {
> > > > >
> > > > > return true;
> > > > >
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > > else if ("SELECT" == oElem.tagName)
> > > > >
> > > > > {
> > > > >
> > > > > var oOptions = oElem.options;
> > > > >
> > > > > var iNumOpts = oOptions.length;
> > > > >
> > > > > for (var j=0;j<iNumOpts;j++)
> > > > >
> > > > > {
> > > > >
> > > > > var oOpt = oOptions[j];
> > > > >
> > > > > if (oOpt.selected != oOpt.defaultSelected)
> > > > >
> > > > > {
> > > > >
> > > > > return true;
> > > > >
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > > return false;
> > > > >
> > > > > }
> > > > >
> > > > > function checkFormStatus(){
> > > > >
> > > > > var frm = document.forms[0];
> > > > >
> > > > > if(isDirty(frm))
> > > > >
> > > > > event.returnValue = "You have entered form Data, or Data has been
> > > entered
> > > > > for you, without submitting this form.";
> > > > >
> > > > > }
> > > > >
> > > > > if ( typeof( window.addEventListener ) != "undefined" ) {
> > > > >
> > > > > window.addEventListener("onbeforeunload", checkFormStatus, false);
> > > > >
> > > > > } else if ( typeof( window.attachEvent ) != "undefined" ) {
> > > > >
> > > > > window.attachEvent("onbeforeunload", checkFormStatus);
> > > > >
> > > > > }
> > > > >
> > > > > [/script]
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Eric
Guest
 
Posts: n/a
#9: Nov 18 '05

re: IsFormDirty


There are properties in the page class that can control this. On postback,
it will pass the dirty state back to the server and maintains it across
postbacks. For controls that use auto-postback, the page's Dirty property
can be set to true in the event handler explicitly so that after returning
to the client, attempts to leave the page will always cause prompting.
There are also properties that allow filtering controls out of the prompting
behavior (such as postback fields and Save buttons) so that you don't get
prompted when they postback but it still maintains the dirty state. The
demo app for the article shows this in action. It uses buttons for the
postback but the concept is the same. If you go to the General.aspx page
and click on the Defaults button, it posts back, stores some values to the
text boxes, sets the Dirty flag to true and returns to the client. If you
now attempt to navigate away from the page without clicking Save, it prompts
you first. If you enter data in the fields first before clicking the
Defaults button, you also get the warning. This can be changed by adding
the button's ID to the BypassPromptIDs list like it does for the two
Enable/Disable buttons and the Save button.

Eric

"Stanley" <webmaster@nospam-glass-images.com> wrote in message
news:O3E5UntAEHA.2584@TK2MSFTNGP12.phx.gbl...[color=blue]
> I tried that solution and it has the same problem as my code. If I have
> autopostback on a dropdown then the user can go away from the page.
>
> -Stanley
>
> "Eric" <MagikNozeGoblin@HotMail.com> wrote in message
> news:e9lnc3lAEHA.2216@TK2MSFTNGP10.phx.gbl...[color=green]
> > See http://www.codeproject.com/aspnet/EWSWebPt2.asp for one possible
> > solution.
> >
> >
> > "Stanley" <webmaster@nospam-glass-images.com> wrote in message
> > news:eHB%23i5IAEHA.2040@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > Hello all,
> > > I have a need to make sure that no users leave a form without being[/color][/color]
> warned[color=green][color=darkred]
> > > that they have un-saved data. I have the script below that I found on
> > > egghead.com but there is an issue with it that if I have a dropdown[/color][/color][/color]
that[color=blue][color=green][color=darkred]
> > > posts back so that I can show another field if the user chooses other[/color][/color]
> then[color=green][color=darkred]
> > > the warning pops up. If I use an attribute on the dropdown to use the
> > > OnChange event and set the bSubmitted=True that takes care of the post[/color]
> > back[color=darkred]
> > > issue but causes another issue. The other issue is now the user can[/color][/color]
> leave[color=green][color=darkred]
> > > the form without any warning. So what I am looking for is a better way[/color][/color]
> to[color=green]
> > be[color=darkred]
> > > able to handle form post backs and still give the user the warning.[/color][/color][/color]
Has[color=blue][color=green][color=darkred]
> > > anyone done this before?
> > >
> > > TIA
> > >
> > > -Stanley
> > >
> > > [script]
> > > var bSubmitted=false;
> > >
> > > function isDirty(oForm)
> > >
> > > {
> > >
> > > if(bSubmitted)
> > >
> > > {
> > >
> > > return false;
> > >
> > > }
> > >
> > > var iNumElems = oForm.elements.length;
> > >
> > > for (var i=0;i<iNumElems;i++)
> > >
> > > {
> > >
> > > var oElem = oForm.elements[i];
> > >
> > > if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
> > >
> > > {
> > >
> > > if (oElem.value != oElem.defaultValue)
> > >
> > > {
> > >
> > > return true;
> > >
> > > }
> > >
> > > }
> > >
> > > else if ("checkbox" == oElem.type || "radio" == oElem.type)
> > >
> > > {
> > >
> > > if (oElem.checked != oElem.defaultChecked)
> > >
> > > {
> > >
> > > return true;
> > >
> > > }
> > >
> > > }
> > >
> > > else if ("SELECT" == oElem.tagName)
> > >
> > > {
> > >
> > > var oOptions = oElem.options;
> > >
> > > var iNumOpts = oOptions.length;
> > >
> > > for (var j=0;j<iNumOpts;j++)
> > >
> > > {
> > >
> > > var oOpt = oOptions[j];
> > >
> > > if (oOpt.selected != oOpt.defaultSelected)
> > >
> > > {
> > >
> > > return true;
> > >
> > > }
> > >
> > > }
> > >
> > > }
> > >
> > > }
> > >
> > > return false;
> > >
> > > }
> > >
> > > function checkFormStatus(){
> > >
> > > var frm = document.forms[0];
> > >
> > > if(isDirty(frm))
> > >
> > > event.returnValue = "You have entered form Data, or Data has been[/color][/color]
> entered[color=green][color=darkred]
> > > for you, without submitting this form.";
> > >
> > > }
> > >
> > > if ( typeof( window.addEventListener ) != "undefined" ) {
> > >
> > > window.addEventListener("onbeforeunload", checkFormStatus, false);
> > >
> > > } else if ( typeof( window.attachEvent ) != "undefined" ) {
> > >
> > > window.attachEvent("onbeforeunload", checkFormStatus);
> > >
> > > }
> > >
> > > [/script]
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread