By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,948 Members | 1,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,948 IT Pros & Developers. It's quick & easy.

How to stop a script?

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I think you'll have to do the transfer before the posting of the alert.
Also only output the alert if Page.IsPostBack == false

Hope that helps

</script>
"Russ" <ru****@eticomm.net> wrote in message
news:qs********************************@4ax.com...
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

Nov 18 '05 #2

P: n/a
I think you'll have to do the transfer before the posting of the alert.
Also only output the alert if Page.IsPostBack == false

Hope that helps

"Russ" <ru****@eticomm.net> wrote in message
news:qs********************************@4ax.com...
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

Nov 18 '05 #3

P: n/a
I think is no much you can do. The script reach the client side and is
cached by the browser. When you hit the back button on the browser it
will just display the old page. Maybe setting some cache options to
force the browser request the page again can resolve this.

Russ wrote:
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

Nov 18 '05 #4

P: n/a
Hi softcoder. Thanks for the reply. But I think you missed one point.
The message is put up and removed (by the user pressing OK). Then,
sometimes, the user will click a button to go to a new page. So the
messagebox is not showing when he leaves the page. But when he
returns to the page up pops the messagebox.

I have put a breakpoint in the code where the message box script is
inserted to make sure the code was not getting called again somehow,
but that is not the case. So using IsPostBack will not help since the
code is not being executed anyway.

Russ

On Thu, 10 Jun 2004 14:06:46 -0700, "softcoder"
<NO**************@soft-haus.com> wrote:
I think you'll have to do the transfer before the posting of the alert.
Also only output the alert if Page.IsPostBack == false

Hope that helps

"Russ" <ru****@eticomm.net> wrote in message
news:qs********************************@4ax.com.. .
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


Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.