Connecting Tech Pros Worldwide Help | Site Map

Page Layout back to default when Browser back button is pressed...

rrocket's Avatar
Member
 
Join Date: Aug 2007
Posts: 116
#1: Aug 24 '09
I have a form that has various tables that are hidden. When the user selects a number from the DDL the corresponding number of tables shows up (using javascript). When the submit button is clicked it carries the values to the next page. The issue is when the user clicks the browser back button the page only shows 1 table (default setup) and not the 3 or 4 it had when it send to the next page.

Is there a way to get the page to keep the correct amount of tables showing with a postback?

Sorry if the title is vague, but it is the best I could come up with. If anyone needs something clarified let me know.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,126
#2: Aug 25 '09

re: Page Layout back to default when Browser back button is pressed...


since you did that with javascript you need some mechanism to 'know' the 'correct numbers of tables' in the first page so onload of it you could either read a cookie or make serverrequest where you have stored the information (DB or it seems that a session would be better) ... then execute the javascript to create the correct amount of tables ...

kind regards
ssnaik84's Avatar
Member
 
Join Date: Aug 2009
Location: Bengaluru, India
Posts: 119
#3: Aug 31 '09

re: Page Layout back to default when Browser back button is pressed...


use querystrings.
that is, on ddlXXX_SelectedIndexChanged, postback page with related value as querystring. it will help you to maintain history.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,126
#4: Aug 31 '09

re: Page Layout back to default when Browser back button is pressed...


it is quite difficult (i would say impossible) to use a querystring with the browsers back- or forward buttons since you don't control them and don't know when the user will click them? as far as i'm aware a querystring is attached to a uri, how could that be done in that case?

kind regards
ssnaik84's Avatar
Member
 
Join Date: Aug 2009
Location: Bengaluru, India
Posts: 119
#5: Aug 31 '09

re: Page Layout back to default when Browser back button is pressed...


Quote:

Originally Posted by gits View Post

it is quite difficult (i would say impossible) to use a querystring with the browsers back- or forward buttons since you don't control them and don't know when the user will click them

ok.. i will explain it..
have you checked history of browser? it stores urls with paramenters (that is querystring) this history is available in your back and fwd buttons.

when you press back button, a page (with particular url and parameters) is loaded.
here you can hide/show tables (on page_load event) by checking querystring value.
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.  string paramValue = Request.QueryString["case"];
  4.  switch (paramValue)
  5.  {
  6.  case 1: showTable1and2();
  7.  break;
  8.  case 2: showTable3and4();
  9.  break;
  10.  :
  11.  :
  12.  }  
  13.  
  14.  
  15.  
and on DropDownList1_SelectedIndexChanged event, you can postback page with appending querystring value or simply
Expand|Select|Wrap|Line Numbers
  1. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  2. {
  3.  Response.Redirect("samepage.aspx?case="+ DropDownList1.SelectedValue);
  4. }
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,126
#6: Aug 31 '09

re: Page Layout back to default when Browser back button is pressed...


hmmm ... sounds reasonable ... i never use querystrings since i always use ajax and so i think that you know what you're talking about :) ... thank you for the insight :)

kind regards,
gits
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#7: Aug 31 '09

re: Page Layout back to default when Browser back button is pressed...


Normally controls such as DropDownLists do not use the query string. In fact they normally call a JavaScript method (__doPostback) when they cause the page to postback to the server.

I don't think that I would use query string.
I'd use HiddenFields instead.

HiddenFields are accessible in both the browser and in your server code. You could set a HiddenField with the number of tables to show whenever you use JavaScript to show them.

Now when the user hits the back button, and the cached version of the page is reactivated....you can should be able to use the values in the HiddenFields to determine how many tables to display.
ssnaik84's Avatar
Member
 
Join Date: Aug 2009
Location: Bengaluru, India
Posts: 119
#8: Sep 1 '09

re: Page Layout back to default when Browser back button is pressed...


Yes, but it's always better not to develop an application, by taking something for granted.. :)
what if user has disabled cache, cookies etc.
I have seen many cyber cafes disable these settings for security reasons..
I still dont get why the hell they do that, instead of using good antivirus package.. :)
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#9: Sep 1 '09

re: Page Layout back to default when Browser back button is pressed...


I just tried running the FireFox under those settings.

When I did, the back button was not available to me at all...so this leads me to conclude that under those settings this "back button pressed" problem doesn't exist.

When you hit the back button of a web browser a cached version of the web page is displayed......

Anything done on the page through Ajax calls, or using JavaScript are not saved in the cached version. A cached version will only be saved for when the full page is sent down from the server...(as apposed to partial page information sent down during Ajax requests).

This is why the JavaScript settings are lost when you move to another page, then hit the back button in the browser...the browser's "cached" version of the webpage is loaded.

In this case, I'm not even sure if the hidden fields would help....

The OP should get back to us regarding whether or not either the query string suggestion, or the hidden fields suggestion worked...

I'm not even sure how you would modify the query string really.

You certainly can't do this using JavaScript...it goes against browser security restrictions.

You'd have to set the Query String server side...in which case you would have to do a Full Page postback to the server...in which case the cached version of the page will end up showing the selected tables anyways and seeing that the tables were set using JavaScript it'd be pointless to full page post back to the server just to tell the server how many tables to display...because then you'd have to have the server set the visibility of the tables over again....you'd have to do double the work.
Reply