R
Russ
I have a form page with a submit button. When the submit is
successfull (good return from web service), I insert a script to put
up a message box saying "Form submitted".
That works fine, but afterwords, if the user uses a different button
to go to a different page (using Server.Transfer), and then uses the
Back button to return, the message box pops up again, even though
nothing more was submitted.
I think I understand why this is happening, the script was inserted in
the page, and the modified page is reloaded when the back button is
used. So how can I prevent this? Is there some way to remove the
script once it has executed?
What I tried:
The script is inserted as part of a LiteralControl, so I tried
removing the control just before leaving the page:
The script was created this way:
String s = "<script>alert('" + msg + "')</script>";
LiteralControl lc = new LiteralControl (s);
lc.ID = "msgBox1";
Page.Controls.Add (lc);
So I tried removing it like this:
IEnumerator enu = Page.Controls.GetEnumerator ();
while (enu.MoveNext()) {
object obj = enu.Current;
if (obj.GetType ().Equals (typeof (LiteralControl))) {
LiteralControl lc = (LiteralControl) obj;
if (lc.ID == "msgBox1") {
Page.Controls.Remove (lc);
break;
}
}
}
It does not work. The enumerator only finds one LiteralControl, but
its' ID string is null. I tried letting the routine delete it anyway,
but the script still popped up the message when returning to the page.
Thanks for any help, Russ
successfull (good return from web service), I insert a script to put
up a message box saying "Form submitted".
That works fine, but afterwords, if the user uses a different button
to go to a different page (using Server.Transfer), and then uses the
Back button to return, the message box pops up again, even though
nothing more was submitted.
I think I understand why this is happening, the script was inserted in
the page, and the modified page is reloaded when the back button is
used. So how can I prevent this? Is there some way to remove the
script once it has executed?
What I tried:
The script is inserted as part of a LiteralControl, so I tried
removing the control just before leaving the page:
The script was created this way:
String s = "<script>alert('" + msg + "')</script>";
LiteralControl lc = new LiteralControl (s);
lc.ID = "msgBox1";
Page.Controls.Add (lc);
So I tried removing it like this:
IEnumerator enu = Page.Controls.GetEnumerator ();
while (enu.MoveNext()) {
object obj = enu.Current;
if (obj.GetType ().Equals (typeof (LiteralControl))) {
LiteralControl lc = (LiteralControl) obj;
if (lc.ID == "msgBox1") {
Page.Controls.Remove (lc);
break;
}
}
}
It does not work. The enumerator only finds one LiteralControl, but
its' ID string is null. I tried letting the routine delete it anyway,
but the script still popped up the message when returning to the page.
Thanks for any help, Russ