Is there way of excluding a page from being registered to the history? If a user visited this page and then navigated to another and hits the 'previous page' button, then I want the user to end up 2 pages back and not on the previous page. I'm aware of how to do this with JS but I'd like to avoid JS if possible.
NavigationManager.NavigateTo has the argument replace for this purpose, set to false by default.
Doc
Related
I have 2 pages in my project. the first page contains 3 lists and page number 2 is for updating some items from page 1. I use to return to the first page
javascript:history.go(-1)
but unfortunately the first page is shown no updates and when I click f5 the changes appear. I want to return to the previous page and reload it. I want to return to the previous page and reload it using javascript or something else not creating a method in my controller
PS: I'm new in asp.net and update methods work fine.
In javascript,
You can use,
window.location.href = "XYZ.html";
to reload the page.
Hope This Will help.
If you always want to go back to the previous page you can use document.referrer to get the url of the previous visited page.
This will give you the url for the page you visited previous. Note that you need to have visited a page before, if not it will return null.
So what you want to do is to have a link containing the value grabbed from document.referrer. Get the link and set the href attribute to document.referrer
<a id="abc" href="test">link</a>
var link = document.getElementById("abc");
link.setAttribute("href", document.referrer);
This creates a link that takes you to the previous page and reloads it on new.
If I have a button on my ASP.NET page which will take you to another page but that page will do something and then will send user back using
Uri uu= Request.UrlReferrer;
if (uu!= null)
Response.Redirect(uu.ToString());
Now Which page event can I use so that when other pages displays I can display a message box.
In short I am running my custom code in a "aspx" page where user is directed on button click, and then after custom code I am sending user back to old page, but it happens so quickly that user doesn't realize that he went on another page, now I want to display a message box after redirect on same page user started from, what to do :S !
More Information
EDIT
Sorry guys but I can't make changes to ASP page where button is at all
:(
I'm a bit unsure about how the Request.UrlReferrer gets set. I think it's a browser implementation detail. So I wouldn't trust on that.
I would go for something like
A.aspx -> Redirects to -> B.aspx
B.aspx -> Redirects to -> B.aspx?message=1
And check if message=1 is set.
But if you want to use the Request.UrlReferrer it should be accessible on Page_Load
If you use it this way, it'll never appear to the client.
Maybe try redirecting back using javascript with a delay so user can be informed
The best thing to do it's add a flag to the redirected page so you can show something special when the flag is turned on
Uri uu= Request.UrlReferrer;
if (uu!= null)
Response.Redirect(uu.ToString() + "?Message=DataHasChanged");
and then in the ASP page
<% if (Request.QueryString["Message"] == "DataHasChanged") { %>
<div class="alert">The data has changed. Please review it or whatever</div>
<% } %>
if users press the browser's back button to reach the prior page, the page should display a message like "web page expired".
can i use javascript for this???
for example:
there are 4 pages in web sites. on page 1,2 and 3 the user can use the back-button, wheras on the 4th page the user gets the desired message.
i thought that i can do this by using counter.
i used following javascript on the master page ..
<script type="text/javascript">
function GoBack() {
window.history.go(+1);
}
</script>
and call the function in body like this:
<body onload="GoBack();">
and on the 4th page_load i do the following:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
it is working for all pages .. but i want to do this only for the 4th page
If you only want it on that page level, and when you use postbacks, then I suggest you simply keep it in ViewState instead of Session state. Session's also still available on other pages, where you might want to have other counters.
You need to keep the variable alive across requests. So one way is to put it in some viewstate or sessionstate. Sessionstate is least preferred. But you can possibly put it in a hidden textbox in the page and simply use it.
Looking at the problem after the much awaited update/edit, I shall suggest you to use SessionState. Please give a try on it.
I have used a query string parameter to redirect from Page 1 to Page 2. From Page 2, i wanted to redirect it to Page 3 if Page 2 has been called from Page 1. What should be the condition to check if the querystring is used??
Please help me out!! Thanks guys!
Ram, this is my interpretation of what you wanted: if user accesses Page2 due to redirect from Page1, the user will be redirected automatically to Page3. If user accesses Page2 directly (without visiting Page1), the user will stay in Page2 (no redirect to Page3).
If this is the case, inside Page1, you can set redirect("Page2.aspx?previouspage=page1"), then in Page2, inside Page_load method, check for the querystring, if previouspage exists and equals "page1", redirect to Page3, else do nothing and Page2 will show up.
You may wish to parse the HTTP_REFERER and see if Page 2 has been called from Page 1. Basically, you would build your Page 2 redirection based on the HTTP_REFERER value. In C#, the value is available using the following:
Page.Request.ServerVariables("HTTP_REFERER")
Put something into the query string of page 2 as well, and check that.
However, you should always move to reduce the number or redirects (some browsers limit at 5 - to prevent the case where while not an exact loop, the browser will redirect for ever - if it already took a couple of redirects to get to your site, then part way through this sequence, it'll stop redirecting). In Page 1 you should redirect to Page 3. If you need something done then do it in Page 1 or Page 3, but note that this is only from the browsers perspective; if you do a server.transfer to page 2 then while the logical pattern for your code is 1 -> 2 -> 3, to the browser it looks like 1 -> 3. In this case you can also check the raw URI if you wanted to know that you had got there by coming from page 1.
Looked at from another way, a redirect is part of your UI. If the user was on page 1 to being with this should have made sense, or there's a bug in your UI. If the user ends up on page 3, then this should also have made sense, or there's a bug in your UI. Now considering this, what is the purpose from the user prespective of page 2? I'm not saying there couldn't be one (I can think of cases where multiple redirects make good sense, esp. if they are of different types, e.g. a moved-permanently followed by a see-other makes sense), but chances are it doesn't and a you could deal with part of it while keeping the flow in the server.
Maybe I am not understanding this right .. but why not redirect directly from page 1 to page 3?
I have a page that requires the user to go through several steps, however step is performed on the same ASPX page with different panels being displayed.
However this is a requirement that each step has a different URL, this could be a simple as a query string parameter, for example:
Step 1:
/member/signup.aspx?step=1
Step 2:
/member/signup.aspx?step=2
Step 3:
/member/signup.aspx?step=3
However I don't want to have to redirect the user to the new URL each time they continue to the next step, this would involve a lot of redirecting and also a switch statement on the page load to work out which step the user is on.
It would be better if I could alter the URL that is displayed to the user when the original request is sent back to the user, i.e. the user click "next" on step 1 the page then does some processing and then alters response so that the user then sees the step 2 URL but without any redirection.
Any ideas would be greatly appreciated.
Could you convert your Panels into steps in a Wizard control?
It would be a little more complicated than you probably want, but you could achieve this effect with the PostBackUrl property of the submitting button. I'm assuming each panel has its own "submit" button, and they could all use this property to "advance" the process. The drawback is that in order to get to submitted controls, you'd need to use the Page.PreviousPage property in order to access any controls and their values.
You could programmatically alter the PostbackUrl property of your 'Next' button on each Page_Load, based on the query string value. This is a bit strange though, as you wouldn't be able to use a standard event handler for the button click, and you'd have to use the PreviousPage property of the Page to get the data from the previous tab.
I'd say challenge this requirement. Why would anyone need to jump into the middle step? If it's a case of displaying the progress to the user, do this on the page, not in the URL.
You require that each step has different URL, than Response.Redirect is the only option. As you want to avoid the redirection, you can use IFrame but IFrame URL is not visible to user on his browser. I think redirect option is ugly(for both SERVER and CLIENT) as in this case, you first post on the page and than get that page. The best solution is POST BACK with some varible tracking step.
You could implement a form or url rewriting so that your urls end up being
/member/signup/step1/
/member/signup/step2/
/member/signup/step3/
To do this use the
HttpContext.RewritePath method which means you can rewrite /member/signup/step1/ to /member/signup.aspx?step=1 for example. See an example here.
I would also use the PRG (post request get) pattern so that each next link posts the form data of that step to the session then redirects the user top the correct next url. this will ensure that the user can navigate back and forth through the steps safely and also the url will remain intact in all your posts.
Check out server.transfer