473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

URGENT - Show message and redirect to a page

In a Button clik event I have this code at the end of the event

Response.Redirect("Page.aspx")

But in this event I must show a message before redirect to the
Page.aspx. I use to show Message this

System.Web.HttpContext.Current.Response.Write("<SC RIPT
LANGUAGE=""JavaScript"">" & vbCrLf)
System.Web.HttpContext.Current.Response.Write("ale rt('A message')" &
vbCrLf)
System.Web.HttpContext.Current.Response.Write("</SCRIPT>")

but I don't show the message alert?? If a delete
Response.Redirect("Page.aspx") line It works!!

Any idea to show message and then redirect to a page.aspx ??

--
Ceci est une signature automatique de MesNews.
Site : http://www.mesnews.net

Nov 19 '05 #1
4 10561
Bnob:
Your best solution is to hook up an onClick event to the button:

Sub Page_Load
if not page.ispostback then
btnClick.Attributes.Add("onClick", "alert('a Message');")
end if
End Sub

The reason your code doesn't work is that when the button is click, it posts
back to the server. At this point you Response.Write the <script stuff, but
that never gets sent to the browser because you response.redirect. If the
method above isn't satisfactory, the only alternative would be, on postback,
output the your javascript, with additional javascript code to redirect the
client to the page...not a nice alternative (and not sure why you'd need
it).

Karl


--
MY ASP.Net tutorials
http://www.openmymind.net/
"bnob" <bn**@bluewin.ch> wrote in message
news:mn***********************@bluewin.ch...
In a Button clik event I have this code at the end of the event

Response.Redirect("Page.aspx")

But in this event I must show a message before redirect to the
Page.aspx. I use to show Message this

System.Web.HttpContext.Current.Response.Write("<SC RIPT
LANGUAGE=""JavaScript"">" & vbCrLf)
System.Web.HttpContext.Current.Response.Write("ale rt('A message')" &
vbCrLf)
System.Web.HttpContext.Current.Response.Write("</SCRIPT>")

but I don't show the message alert?? If a delete
Response.Redirect("Page.aspx") line It works!!

Any idea to show message and then redirect to a page.aspx ??

--
Ceci est une signature automatique de MesNews.
Site : http://www.mesnews.net

Nov 19 '05 #2
Karl Seguin avait prétendu :
Bnob:
Your best solution is to hook up an onClick event to the button:

Sub Page_Load
if not page.ispostback then
btnClick.Attributes.Add("onClick", "alert('a Message');")
end if
End Sub

The reason your code doesn't work is that when the button is click, it posts
back to the server. At this point you Response.Write the <script stuff, but
that never gets sent to the browser because you response.redirect. If the
method above isn't satisfactory, the only alternative would be, on postback,
output the your javascript, with additional javascript code to redirect the
client to the page...not a nice alternative (and not sure why you'd need
it).

Karl


--
MY ASP.Net tutorials
http://www.openmymind.net/
"bnob" <bn**@bluewin.ch> wrote in message
news:mn***********************@bluewin.ch...
In a Button clik event I have this code at the end of the event

Response.Redirect("Page.aspx")

But in this event I must show a message before redirect to the
Page.aspx. I use to show Message this

System.Web.HttpContext.Current.Response.Write("<SC RIPT
LANGUAGE=""JavaScript"">" & vbCrLf)
System.Web.HttpContext.Current.Response.Write("ale rt('A message')" &
vbCrLf)
System.Web.HttpContext.Current.Response.Write("</SCRIPT>")

but I don't show the message alert?? If a delete
Response.Redirect("Page.aspx") line It works!!

Any idea to show message and then redirect to a page.aspx ??

--
Ceci est une signature automatique de MesNews.
Site : http://www.mesnews.net

It doesn't work because the alert message don't be showed in all case.

I make a test and if it's false, I show the alert message, if true I
don't show the message. With attributes "onclick" the alert message is
always showed

--
Ceci est une signature automatique de MesNews.
Site : http://www.mesnews.net

Nov 19 '05 #3
bnob:
In that case you either implement your "test" on the client - which I don't
think is a particulary good idea, or you use the alternative method I
suggested. The problem is that it's one extra page hit. You could also
show the message on Page.ASPX (the page you redirect to) when it loads...
Response.Redirect("Page.aspx?showMessage=true");

in Page.aspx, on load, check if showMessage = true, if so, display the
message.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"bnob" <bn**@bluewin.ch> wrote in message
news:mn***********************@bluewin.ch...
Karl Seguin avait prétendu :
Bnob:
Your best solution is to hook up an onClick event to the button:

Sub Page_Load
if not page.ispostback then
btnClick.Attributes.Add("onClick", "alert('a Message');")
end if
End Sub

The reason your code doesn't work is that when the button is click, it posts back to the server. At this point you Response.Write the <script stuff, but that never gets sent to the browser because you response.redirect. If the method above isn't satisfactory, the only alternative would be, on postback, output the your javascript, with additional javascript code to redirect the client to the page...not a nice alternative (and not sure why you'd need
it).

Karl


--
MY ASP.Net tutorials
http://www.openmymind.net/
"bnob" <bn**@bluewin.ch> wrote in message
news:mn***********************@bluewin.ch...
In a Button clik event I have this code at the end of the event

Response.Redirect("Page.aspx")

But in this event I must show a message before redirect to the
Page.aspx. I use to show Message this

System.Web.HttpContext.Current.Response.Write("<SC RIPT
LANGUAGE=""JavaScript"">" & vbCrLf)
System.Web.HttpContext.Current.Response.Write("ale rt('A message')" &
vbCrLf)
System.Web.HttpContext.Current.Response.Write("</SCRIPT>")

but I don't show the message alert?? If a delete
Response.Redirect("Page.aspx") line It works!!

Any idea to show message and then redirect to a page.aspx ??

--
Ceci est une signature automatique de MesNews.
Site : http://www.mesnews.net

It doesn't work because the alert message don't be showed in all case.

I make a test and if it's false, I show the alert message, if true I
don't show the message. With attributes "onclick" the alert message is
always showed

--
Ceci est une signature automatique de MesNews.
Site : http://www.mesnews.net

Nov 19 '05 #4
The HttpResponse.Redirect emits the HTML code need to redirect to the
redirection url. If smart navigation is enabled and a post back has been
done the following HTML is emitted:
<BODY><ASP_SMART_NAV_RDIR url="Page.aspx"></ASP_SMART_NAV_RDIR></BODY>

Otherwise the following code is emitted:
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="Page.aspx">here</a>.</h2>
</body></html>

An HTTP redirect header is also sent, so the emitted HTML won't be displayed
in most modern browsers.
To show your message before the redirection cannot use
HttpResponse.Redirect, instead you must emit the HTML code to display the
message and then redirect to the target url.

This code can look like this:
<html><head><script language="JavaScript">alert("A
message");location.replace("Page.aspx");</script></head><body></body></html>

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sean Pinto | last post by:
My hosting company has an automatic redirect page called /missing/missing.php and I want to log all of the page not founds that result in a redirection to missing.php. I can't seem to find out how...
4
by: Michael | last post by:
Hi, I create site with a prefix FramSet layout. The main page contains HTML <Form> function like this <Form name=my_form method=post action=my_action.asp> <input name=search_string ...
1
by: Mike Moore | last post by:
We have a custom validator that should validate when there is a duplciate record, but the problem is that the show message box doesn't display. Why suggestions as to why?
2
by: Raghu Raman | last post by:
Hi, In my asp .net page am using many controls and a grid.i populate many html controls innside the grid dynamically .if i click the grid ,it wll go to other page using onclick client side...
1
by: Dominique | last post by:
Hi, I'd like to show an html page in a form but without use the webform control because I can't create my own context menu detecting the link right click, and so on ... Does any one have an...
1
by: thirunavukarasukm | last post by:
i created one web form the form contain two label box and text box in the form one button is placed i click the button the page redirect to next page window.location.href="fdfgd.com";
4
by: sva0008 | last post by:
Hi, How do i redirect page in the javascript function? I am using Response.redirect ("LoadDetail_DS.asp"); but it gives me error : 'Response' is undefined. Thanks
0
by: kayyum | last post by:
how to show message in asp.net in code behind for web page using C#
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.