javascript:history.back() on pages and not events - asp.net

I have an ASPX page that contains a link to "javascript:history.back()"
The problem is that page contains a gridview that changes with events (ex. a column is sorted). Now when I click the link to "javascript:history.back()", it just reverses the event but instead I want to go back to the last page (bypassing all the events).
Is there a simple way to do this?

You'll have to save the referring page's URL when your page first gets called. Then use this URL in your "Back" links.

Related

Refresh content page when master page is updated

My site uses a Calendar control to determine what date to get data for.
Because this calendar should be visible on every page, I've placed it on my MasterPage.
If the date on the calendar is changed, it should cause the data shown in the Content page to be updated with data specific for the new date. Essentially, it should cause the page to be reloaded.
Because the calendar is on the MasterPage, that's where I'm putting the SelectionChanged event handler, but I'm not sure how to "reload" the content page from here. All I can think of is a Response.Redirect, and I'm not sure if that's the best option.
Can anyone give me any suggestions?
Decided I'd simplify this and make the master page element a hyperlink that redirected to a page that had the calender on it and "Save" button on it.
I found this much easier to manage...
The calendar loads with today's date, allows the user to select another date and the save button writes the new selected date into a session variable read for the data that is to appear on all the content pages.
It means the user has to specially go away from what he/she is currently doing in order to set the date, but I actually prefer it this way.

hyperlink and responce.redirect

I am new to asp.net and i need to know
whats the differences between a button with response.redirect behind it
and a hyper link ? they get you both to the page but one is server side while the other is not
is it the only difference
and when it is best to use either one of them
A hyperlink render a link to the given NavigateUrl in the browser. When the user clicks on it, the browser directly goes to the destination.
A button with redirect renders a button which does a postback using javascript. When the user clicks on it, a postback is done to the same page and the browser is instructed to go to another URL using Response.Redirect.
The main difference is that the second solution loads the same page again, while the first solution goes directly to the destination. With a button you can run some code before redirecting, or redirect to a different URL based on the information in the postback. Because it loads the original page before loading the destination page, it is a bit slower.
With a hyperlink, the visitor will see where the hyperlink leads to. With a button you can not see this. A hyperlink is thus better for search engines, because they will follow a hyperlink and will not follow a button.
If you know the URL in advance and you do not want to run extra code when the user clicks on something, use a hyperlink. Else, use a button.
A hyperlink is a link which will redirect you somewhere in the same tab or in a new tab when you click on it.
In case of response.sendredirect() the user's browser is redirected to a link sent by the server depending on your business logic.(the link may belong to some other domain).
hope that helps
Hyperlink control
This is server control use for navigation to another page specified in the NavigateURL property. Hyperlink control doesn’t expose any server side event.
Response.Redirect method
This method is used to navigate to another page from code. You can use this method to navigate from a Linkbutton or ImageButton control.

problme with changing control values from a diffrent page

i am using c# aspx , what i'm trying to do is to change a button.visible value from another page.
my page is build from 1 main page and 2 iframes ,the main page uses as a menu, iframe 1 is a login page and iframe 2 is the pages of my site.
on the menu page i have an admin control button which allows me to edit my database , this button visibility is false by default, then , if an administrator is logged in at the login iframe, the button should get visible.
i have tried in so many way to change that button but none worked ,
what i have tried so far:
1) send the button in a session ,recive on other page and change -not working
2) send the whole page and change - not working .
3) make the button public static and change - not working .
i have noticed that even when i change the text on the button on the other page ,on the menu page (the page where the button lays) the button didn't changed it's text.
anothere thing i have noticed is when i press a button on a page , the page is sort of updating (like refreshing but keeps values) , is there a way to make this kind of update manualy?
thanks .
I am assuming from your description that you are trying to change the visibility of the button on the other frame from a post back within the log in frame. The short answer is that this will not work because there is nothing being sent from the server to the client for the other frame.
Your would need to set the visibility of the button in a post back of the page containing the button (which is in the other frame).
It may be better to remove the use of frames and use a master page to provide the log in portion of your page/site as this would allow you to change the visibility of the button in a post back for any page on your site.
For the attempts that you have tried, all three of these should be avoided because the controls are recreated every post back when the page is recreated and will also be disposed every post back in the unload of the page. Since the control and page would be disposed on the first request if you access it on a subsequent call to the server there is no guarantee that the state of the page or control is valid.
For more details on the life cycle of a page, look at the ASP.NET Page Life Cycle Overview:
http://msdn.microsoft.com/en-us/library/ms178472.aspx

Modifying the Postback URL to ht a page anchor

I have a page with several gridviews. For usability, I have put these gridviews into a series of jquery tabs. Tabs works by creating anchor links that go to containers with certain ids, so after clicking on a given tab, the url might change from
host.com/page.aspx
to
host.com/page.aspx#tab2
The issue is that if any elements inside the tabs cause a postback, like trying to sort or page the grid for example, upon loading, the selected tab is lost, and reverts back to the first tab in the list. So in that case I would have sorted the right grid, but I'd have to click the correct tab again to see it.
To fix the issue, I want to track what anchor I'm at as the postback occurs, so that I can change the url I'm loading to include it. The only way I can think to do it is a Redirect, which I really don't want to incur the cost of.
Is there some better way to specify which anchor to load on postback?
On the forms onsubmit event, modify the action attribute to include the relevant anchor (which you'll need to keep track of yourself)
If the page is posting back to itself then instead of making the post back to foo.aspx you need to make it postback to foo.aspx#anchor.
You could also do this via cookies if you must but anchors is much better. Cookies are more useful for things like customizing the Yahoo page to focus on a particular tab on each visit.

Anchoring to clicked item in asp.net page

I've a datagrid on an asp.net page "A" which shows different customer orders.
On clicking on one any row/OrderId,user is redirected to another page "B" which displays order details.
When user clicks "Back to Page A" on page B,I need to have the same order Id "anchored" on page A.
How do i achieve this functionality in asp.net?
Thanks for reading.
Joel's answer is correct, however, if you have a more complicated scenario you could do the following.
Modify the display on Page A to render an <a name="myRecord" /> for each row of the grid.
On page B, you can redirect back to page A and pass #myRecord at the end of the url, to navigate to the specific entry.
In most browsers, the back button remembers where your were in the page. So a simple javascript:history.go(-1) should do just fine, and anyone who doesn't have javascript enabled can just click the back button.

Resources