473,385 Members | 1,329 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,385 software developers and data experts.

Response.redirect inside a Timer Event

Hi everybody,
I'm using a system.timers.timer object like this:

Dim aTimer As New System.Timers.Timer()

In my page_load event I use this:
aTimer.Interval = 5000
aTimer.Enabled = True
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
.....
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As
System.Timers.ElapsedEventArgs)
response.redirect(....)

End Sub.
Well, I recieved an error in response.redirect sentence,
"response is not available in this context".

I can see that httpcontext.current is nothing and I don't know why.

If I use server.transfer instead of response, I get the same error.
How could I do this without using javascript either Meta Tags?
Why do it happen this?

Regards,

Alberto.


Oct 23 '07 #1
7 11527
Sorry,

But you will have to use client side script (with that timer, the page
will be already freed):

Something like:

protected void Page_Load(object sender, EventArgs e)
{

string destinationURL = "http://www.mysite.com"
Response.AppendHeader("REFRESH", "5;URL=" + destinationURL);
}
You can use as well a javascript solution with a timer, on
registerstartupscript.
--
/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------


"albertosoria" wrote:
Hi everybody,
I'm using a system.timers.timer object like this:

Dim aTimer As New System.Timers.Timer()

In my page_load event I use this:
aTimer.Interval = 5000
aTimer.Enabled = True
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
....
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As
System.Timers.ElapsedEventArgs)
response.redirect(....)

End Sub.
Well, I recieved an error in response.redirect sentence,
"response is not available in this context".

I can see that httpcontext.current is nothing and I don't know why.

If I use server.transfer instead of response, I get the same error.
How could I do this without using javascript either Meta Tags?
Why do it happen this?

Regards,

Alberto.

Oct 23 '07 #2
"albertosoria" <al**********@discussions.microsoft.comwrote in message
news:B0**********************************@microsof t.com...
I can see that httpcontext.current is nothing and I don't know why.
If I use server.transfer instead of response, I get the same error.
Why do it happen this?
WebForms (i.e. ASP.NET) apps are not the same as WinForms apps. Because of
the fundamental architecture of the web, they are stateless. This means that
they work in a request / response scenario - a client sends an HttpRequest
to a webserver, the webserver process the HttpRequest and sends back an
HttpResponse. After the HttpResponse has been sent down to the client,
nothing else happens between server and client until / unless the client
sends back another HttpRequest.

When a client makes a request to an aspx page, the Page object goes through
a predefined lifecycle firing events such as Page_Load etc. The very end of
this predefined lifecycle involves sending the HttpResponse down to the
client and then unloading the page. Once the page is unloaded, it's gone...
How could I do this without using javascript either Meta Tags?
Timers in ASP.NET are hugely problematic, and are almost always the wrong
answer. You could, I suppose, create a Timer object and store in Application
cache, but of course it would then stop when the final session times out. To
prevent this, you could keep accessing the website every 15 minutes or so
just to keep it alive...

What are you actually trying to achieve with this timer...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 23 '07 #3
Thanks Braulio, but it's more complicated...

I have a .aspx page with a <IFRAMEtag inside which source connect to other
server.

My timer is on the .aspx page, and I need to wait until a value exist in my
database, so I use the timer event to search in the database for this value
each 5 seconds.

In the moment I get this value, I need to do the redirection, not before,
so, your solution is not valid for me, because I don't know how many time I
need to wait for the value.

Any idea?

Thanks.
"Braulio Diez" wrote:
Sorry,

But you will have to use client side script (with that timer, the page
will be already freed):

Something like:

protected void Page_Load(object sender, EventArgs e)
{

string destinationURL = "http://www.mysite.com"
Response.AppendHeader("REFRESH", "5;URL=" + destinationURL);
}
You can use as well a javascript solution with a timer, on
registerstartupscript.
--
/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------


"albertosoria" wrote:
Hi everybody,
I'm using a system.timers.timer object like this:

Dim aTimer As New System.Timers.Timer()

In my page_load event I use this:
aTimer.Interval = 5000
aTimer.Enabled = True
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
....
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As
System.Timers.ElapsedEventArgs)
response.redirect(....)

End Sub.
Well, I recieved an error in response.redirect sentence,
"response is not available in this context".

I can see that httpcontext.current is nothing and I don't know why.

If I use server.transfer instead of response, I get the same error.
How could I do this without using javascript either Meta Tags?
Why do it happen this?

Regards,

Alberto.


Oct 23 '07 #4
First of all, thanks Mark,

I'll try to explain you what I want to do.

I have an .aspx page with an <IFRAMEtag inside. The Source attribute of
this tag connect to an external server and this server will insert a value in
a database.

I need to wait until this value appear, but I don't know when it will happen
(but I'm sure it will), so I use the timer to search in the database each
five seconds, and when I get to catch the value, I have to do the
response.redirect, not before.

Any idea how can I do that?

"Mark Rae [MVP]" wrote:
"albertosoria" <al**********@discussions.microsoft.comwrote in message
news:B0**********************************@microsof t.com...
I can see that httpcontext.current is nothing and I don't know why.
If I use server.transfer instead of response, I get the same error.
Why do it happen this?

WebForms (i.e. ASP.NET) apps are not the same as WinForms apps. Because of
the fundamental architecture of the web, they are stateless. This means that
they work in a request / response scenario - a client sends an HttpRequest
to a webserver, the webserver process the HttpRequest and sends back an
HttpResponse. After the HttpResponse has been sent down to the client,
nothing else happens between server and client until / unless the client
sends back another HttpRequest.

When a client makes a request to an aspx page, the Page object goes through
a predefined lifecycle firing events such as Page_Load etc. The very end of
this predefined lifecycle involves sending the HttpResponse down to the
client and then unloading the page. Once the page is unloaded, it's gone...
How could I do this without using javascript either Meta Tags?

Timers in ASP.NET are hugely problematic, and are almost always the wrong
answer. You could, I suppose, create a Timer object and store in Application
cache, but of course it would then stop when the final session times out. To
prevent this, you could keep accessing the website every 15 minutes or so
just to keep it alive...

What are you actually trying to achieve with this timer...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 23 '07 #5
"albertosoria" <al**********@discussions.microsoft.comwrote in message
news:98**********************************@microsof t.com...
I'll try to explain you what I want to do.

I have an .aspx page with an <IFRAMEtag inside. The Source attribute of
this tag connect to an external server and this server will insert a value
in
a database.

I need to wait until this value appear, but I don't know when it will
happen
(but I'm sure it will), so I use the timer to search in the database each
five seconds, and when I get to catch the value, I have to do the
response.redirect, not before.
Firstly, you didn't mention any of the above in your original post...
Any idea how can I do that?
1) Forget the server-side timer approach

2) Set the page inside the iframe to refresh itself using the meta tag

3) Add the following to the Page_Load of the page inside the iframe:

protected void Page_Load(object sender, EventArgs e)
{
bool blnValueExists = <however you check your database for this value);

if (blnValueExists)
{
ClientScript.RegisterStartupScript(GetType(), "redirect",
"parent.location.href='page2.aspx';");
}
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 23 '07 #6
Mmmm...

I would call a web service/page method from javascript to ask if the
database is ready (the best way to achieve this is using AJAX ASP .net)

http://www.tipsdotnet.com/ArticleDet...subarea=ASPnet

If you can't you can perform this query using XMLHttpRequest (beware here,
in IE and firefox you would have differetn implementations).

Good luck

/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------


"albertosoria" wrote:
Thanks Braulio, but it's more complicated...

I have a .aspx page with a <IFRAMEtag inside which source connect to other
server.

My timer is on the .aspx page, and I need to wait until a value exist in my
database, so I use the timer event to search in the database for this value
each 5 seconds.

In the moment I get this value, I need to do the redirection, not before,
so, your solution is not valid for me, because I don't know how many time I
need to wait for the value.

Any idea?

Thanks.
"Braulio Diez" wrote:
Sorry,

But you will have to use client side script (with that timer, the page
will be already freed):

Something like:

protected void Page_Load(object sender, EventArgs e)
{

string destinationURL = "http://www.mysite.com"
Response.AppendHeader("REFRESH", "5;URL=" + destinationURL);
}
You can use as well a javascript solution with a timer, on
registerstartupscript.
--
/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------


"albertosoria" wrote:
Hi everybody,
I'm using a system.timers.timer object like this:
>
Dim aTimer As New System.Timers.Timer()
>
In my page_load event I use this:
aTimer.Interval = 5000
aTimer.Enabled = True
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
....
>
>
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As
System.Timers.ElapsedEventArgs)
>
>
response.redirect(....)
>
End Sub.
>
>
Well, I recieved an error in response.redirect sentence,
"response is not available in this context".
>
I can see that httpcontext.current is nothing and I don't know why.
>
If I use server.transfer instead of response, I get the same error.
>
>
How could I do this without using javascript either Meta Tags?
Why do it happen this?
>
Regards,
>
Alberto.
>
>
>
>
>
>
Oct 23 '07 #7
Many thanks for your gelp Mark, but I afraid that it doesn't work.

It is even more complecated, I'll try to give you all details:

1.) I have a masterpage with a contentplaceholder.
2.) The contentplaceholder is an .aspx with a <IFRAMEtag (i.e page1.aspx)
3.) The <IFRAMEsource is to another .aspx (i.e. page2.aspx)
4.) In OnLoad Event of page2.aspx is built a Form in runtime and it is
submited automatically. The Action of this form connect to an external page.

So, when I see the sourcecode, I see the request to the form submit, that
is, I have no control to this page. The URL is page2.aspx, but the sourcecode
is the request to the form submited.

After the form is submited to an external page, is processed there and if it
is ok, it will insert a value on a database.

Meanwhile, I have to be waiting for this value, but only I have control of
page1.aspx and MasterPage. Then, when the value is inserted I have to
redirect to another page, for that, I was using a timer.

I can't use OnLoad on page2.aspx, because when the form is submited, the
code is rewritten for the external server, so the meta tag disappear and I
can't write any code because I have no control of that.

Do you understand what I mean?
"Mark Rae [MVP]" wrote:
"albertosoria" <al**********@discussions.microsoft.comwrote in message
news:98**********************************@microsof t.com...
I'll try to explain you what I want to do.

I have an .aspx page with an <IFRAMEtag inside. The Source attribute of
this tag connect to an external server and this server will insert a value
in
a database.

I need to wait until this value appear, but I don't know when it will
happen
(but I'm sure it will), so I use the timer to search in the database each
five seconds, and when I get to catch the value, I have to do the
response.redirect, not before.

Firstly, you didn't mention any of the above in your original post...
Any idea how can I do that?

1) Forget the server-side timer approach

2) Set the page inside the iframe to refresh itself using the meta tag

3) Add the following to the Page_Load of the page inside the iframe:

protected void Page_Load(object sender, EventArgs e)
{
bool blnValueExists = <however you check your database for this value);

if (blnValueExists)
{
ClientScript.RegisterStartupScript(GetType(), "redirect",
"parent.location.href='page2.aspx';");
}
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 23 '07 #8

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

Similar topics

3
by: Paul | last post by:
I'm not getting the results I want when I use Response.Redirct in a ASP page. I enter this line of code in a asp page from domain1.com. Response.Redirect...
4
by: Max Dupenois | last post by:
I've seen numerous articles with similair (similar sp?) titles to this in my search.. unfortunately none of them seem to contain what i want, (or if they do i need someone to point out my stupidity...
3
by: Sha Crawford | last post by:
I'm using an access xp form to present stimuli which participants in an experiment must respond to as quickly as they can. I need to time their responses as accurately as possible. At the moment I...
6
by: DotNetGruven | last post by:
I've got a page that does a search... There is an ImageButton on it that allows the user to reset the search. The Click Handler for the button clears out the Data and then redirects to the same...
2
by: Sam Miller | last post by:
I have a submit button. In the event handler for that button I connect to database and write all the control values to the db. Then I have a response.redirect after the Conn.Close to leave the...
10
by: Niggy | last post by:
I get an error - any help appreciated. System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object...
5
by: venner | last post by:
I'm having an issue with an ASP.NET website after upgrading to ASP.NET 2.0. The website makes use of a central authentication service (CAS) provided at the university I work for. Each page checks...
5
by: =?Utf-8?B?d2ViZ3V5QGNvbW11bml0eS5ub3NwYW0=?= | last post by:
We have been running into some problems where using Response.Redirect causes the page to hang and it never actually redirects. Here's the scenario: User opens the page, selects an item from the...
4
by: nkoier | last post by:
Hi, I've been going crazy trying to figure out what's wrong with our Asp.Net 2.0 intranet site. At the very top of our main page I provide a TextBox and a Button for submitting Google searches....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.