0

I have a simple web page - I want the page to refresh after n minutes AND I need to have a server side function occur when the page refreshes. I am using

<meta http-equiv="REFRESH" content="20" />
<meta http-equiv="pragma" content="no-cache" />

in the header .. to accomplish this.

I want to force the PostBack when the page refreshes and I need to make it as SIMPLE as possible - someone else will be maintaining the code later and they are not fluent in c# or html; so I need to follow KISS a bit more strictly.

I would like to avoid adding update panels ajax etc - and continue with the refresh meta tag as it is in (.aspx) text file and they can handle text easier.

How can I force a Postback when the page refreshes ?

EDIT I do not want to send anything back to the server. I want the server itself to rerun a query that sends data to the client. The query has a dynamic parameter set in a dictionary - the dictionary is initially loaded with some csv values from a web.Config AppSettings . On Each refresh an index value needs to be incremented [Dictionary Key] and the query run again with the new value.

Ken
  • 2,518
  • 2
  • 27
  • 35
  • 2
    Meta-refresh, by definition, sends no data to the server except what's in the actual element. If you wish to send data back to the server, you'll need to do so by either triggering a post of the form, or by using ajax. – Dave Feb 26 '16 at 17:01
  • @Dave - please see my edit. – Ken Feb 26 '16 at 17:47
  • So you don't necessarily care that it's a postback, you just want the page to reload? – mason Feb 26 '16 at 17:48
  • So force that query to run even if Page.IsPostBack is false, then? – Dave Feb 26 '16 at 17:55
  • @Dave - sorry for my delay.. Yes that is correct I am not concerned about Postback - this is a simple system displayed full screen as an info kiosk . The page refresh should cause a new request for query - I have been experimenting with Session.IsNewSession - but it messes up using ViewState; I was looking here:http://stackoverflow.com/questions/621549/how-to-access-session-variables-from-any-class-in-asp-net which looks like a good route to go - but I am at a loss how to use his wrapper in the actual page. – Ken Feb 26 '16 at 22:54
  • All you need to do is add your logic to your `Page_Load` method and make sure it's not wrapped in an `IsPostBack` check. – mason Feb 27 '16 at 14:25
  • @mason in the initial load of the page !Postback I am creating some initialization information which I need to store this is not a postback because it is a page load event.. I can not have this code run in a normal refresh - so I am in effect trying to determine a refresh event in order to change the query - my dictionary has an int key which I increment on every page refresh. Maybe I am missing something here. My viewState info gets lost between refreshes - so I started using a session ; it works but then times out and page just disappears. So I am trying to restart that session. – Ken Feb 28 '16 at 22:51
  • If you use meta-refresh, then by definition it is not a postback and is in fact a new load of the page. You're either going to have to either run your code when it's not a postback, or stop using metarefresh. – mason Feb 29 '16 at 00:15
  • @mason I used Session.IsNewSession - created an iframe page with meta refresh to update session so it never ends the session - its a kiosk no user interaction. I store my data in the Session so I never reload the configuration and parameters. I get them on Session start and that is it. It is working like it should - ran 24 hours with no errors and no shutdown. – Ken Feb 29 '16 at 13:27

0 Answers0