Need to Prevent the Browser back button - c#

I have to prevent browser back button.
for example I have two page((using xml & xslt))
Login.aspx
Page1.aspx
1 .while loading Login page I have created one guid and stored in Login.aspx hidden variable
while loading Page1.aspx I have Created another guid and stored in page1.aspx hidden variable
when user clicks browser back button I an sending hidden variable from page1.aspx
to Login.aspx while loading here i need check guids to confirm it is from page1.aspx
and redirect to same page.
// I have to prevent browser back button(any suggestion is appreciated)

This works for me on my asp.net website.
In the login.aspx html, add "onload="window.history.forward();" to the body statement:
<body onload="window.history.forward();">
Note: This only kicks in after the user interacts with Page1.aspx. It will send you user back to Page1.aspx if they use the previous page browser function on Page1.aspx.

Related

Relation between master page and non master page

There is a page Login.aspx having a Label control as "Lbl_LoginExpired".
There is also a MasterPage.
I want to change the text of "Lbl_LoginExpired" from within the Master Page.
How can i achieve this?
Note:
1) Login.aspx is NOT a Content page.
2) Label label1=new (Label)Login.FndControl("Lbl_LoginExpired")
is NOT working in MasterPage.
If there is no master page- content relationship between these 2 pages. I think your options are limited. Also i am assuming Lbl_LoginExpired is not a part of an user control that you can register in both pages. I would recommend using Session object to pass this information between these 2 pages.
Hence in your master page
Session["expiredtext"] = "Your login has been expired";
And in your login pag check this session value whether it is null or not and show the content of it.
Lbl_LoginExpired.Text=Session["expiredtext"]?.ToString();
Also do not forget to reset (or abonden session when user logs out)

Session timeout - Redirect user to same page on logging

In my Asp.Net webpage application when session timeout occurs the page will redirect to the login page and when we login again it goes to the home page.
But I want to redirect to the previously active page (where the session timeout occurs) instead of redirecting to the home page by default.
Is there is any way to achieve this.
Hello you can do following thing
When session expires at that time you can redirect user from that page to logged in page with below query string
Response.Redirect("Login.aspx?url=page.aspx");
Where Page.aspx will be your current page name. you have to write this code on each page's load Event before if(!ispostback) condition.
and at time of logged in button click you can do
if (Request.QueryString["url"] != null)
{
Response.Redirect(Request.QueryString["url"].ToString());
}
after making query for user name and password before your redirect to default page.

Redirect back to same application as if typing the URL in address bar? (Not a Postback)

Silly question,
Is there a way to redirect an application back to it's self from a button or a hyperlink (without a simple postback), as if you were typing the application's url in the address bar for the first time?
The reason I ask is because I have an application with a parent web form and then Telerik RadMultiPage that renders each page (or web user control) one at a time. I do not have the option to use the "RenderSelectedPageOnly" property in this case because I want the user to be able to navigate between pages with the TabStrip.
On the very last page, I want the user to be able to start the application all over, as if visiting the URL for the first time. The application is session based and when landing on the last page, I clear all session variables (Personal Information). On the last child page, I have put a button with Response.Redirect("default.aspx", true); event. The problem is that previous pages contain if statements that basically listen for certain session variables and act accordingly.
When I run the Response.Redirect("default.aspx", true); on the last PageView, I get "object reference not set to an instance of an object". I know it's because of Session variables that no longer exists but this happens because all MultiPage views are still loaded on a postback.
Any way to just simulate typing a url in the address bar and hitting submit?
You can accomplish this very easily with javascript.
Javascript
function ReloadMe() { window.location = window.location.href; }
HTML
<input type="button" value="Reload Me" onclick="ReloadMe()" />

How to check browser back button is clicked when child window is opened?

I have to fix one issue in our application that, If child window is opened and user clicks on Browser back button i need to redirect to page asking username and password.
we have 400 aspx pages so just i need to modify in master page. I have code like below
function initPage(){
checkback();
}
This function is written in external javascript file and used in Master Page.
checkback function contains code like below
if (document.forms[0].cprotection.value=='1')
{
document.forms[0].pagecode.value=0;
document.forms[0].act.value='backpressed';
document.forms[0].submit()
}
The above code is working fine for parent window but not if i open child window.
backpressed is keyword am using to check in class file to redirect to page asking username and password. Please help me out in fixing this issue. Thanks in advance
You could add a variable to the session when the child window is loaded and if the user clicks back you would check the session to see if the variable that the child window added to session is nothing inside whichever pages load function and if it is then load normally, if its not redirect to the login page.

Postbackurl Vs Response.Redirect (losing data)

I have a button in my aspx page, which in code behind the value of postbackurl gets set. I updated the code to add click event handler and added Response.Redirect code to redirect user to the page once the button is clicked. The only reason i ended up adding click event was because i had to add some extra logic when the button was clicked including redirecting to same url, that was used in postbackurl. The page does get redirected on click however it seems like all the hidden fields from the field gets lost once the form get redirected to the url.
Is there anyway i can submit the form without loosing the hidden data.?
Maybe one way you can solve this problem is to use the server side Transfer() call.
http://msdn.microsoft.com/en-us/library/540y83hx(v=vs.85).aspx
In most cases I've seen what you really want to do is pass the information for the new page using URL parameters. Take all the stuff the new page needs and put it into the url (encrypt if it is security sensitive).
If the only issue you are having is when you want to stay on the same page, this is simple, just have the click event handler return without doing a response.redirect or a transfer.
Post the code if this is not working for you.

Categories

Resources