This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
detect back button click in browser
I have two pages, Page1 and Page2. When moving from Page1 to Page2 by clicking a link, I tend to store the conditions required to restore the state of Page1 on clicking browser back button when on Page2.
I am using the below function to clear the cache,
protected override void OnInit(EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetExpires(DateTime.MinValue);
base.OnInit(e);
}
so that I can reload the page based on stored conditions in the cookie. But the issue is how to identify if I have pressed the browser back button or the menu link to come to Page1.
Update:
i just landed on this link detect back button click in browser but it doesn't work for me
Please explain your problem, not your solution. Because you set the cacheability of your page to none, the browser will simply re-issue an unconditional request for the page. This is no different than clicking a link to that page and will not be detectable.
If your problem is that you don't know how to set form data when someone revisits a page, you could use a session like this (psuedo):
if (!String.IsNullOrEmpty(Session["Username"]))
{
UsernameTextbox.Text = Session["Username"];
}
If you want to show a clear form when the link to that page is clicked, you could set a query parameter like reset=true, which will clear the session data and show a blank form.
Related
Please be assume that I have already login.
I have two pages. PickupList.aspx. There has a button named as "New".
When I click New button page url changed as PickupJobForm.aspx?mode=new
But loading time is not finish and form not appear.
After logout the application. And I copy and paste this url PickupJobForm.aspx?mode=new. And I press enter key from keyboard. Login form appears. After I logIn ready, I can see the create job web form.
What is the differences?
One more info is that our client computer is window 10. And we are using the Trend Micro Apex One.
protected void rbtnNew_OnClick(object sender, EventArgs e)
{
Response.Redirect("~/PickupJobForm.aspx?mode=new", false);
}
Project and problem explanation
In my case I have a page which instructs the user how to move a certain machine. This page is supposed to be a modal page since the page should not be navigated away from without performing or completely canceling the action.
I have a mainpage with a listview which opens the details page of any of the items contained in the listview on click through the onSelect method:
Navigation.PushAsync(new FooPage(string Name)); /* gets called in the
onSelect method if selection is not null*/
The model is retrieved within the details page's viewmodel after passing the name to it and then using a model manager injected into the viewmodel with Unity to retrieve it.
-- we now both have a mainpage and detailspage on the stack which of only the detailspage has a backbutton --
On the detailspage we have a button called "Teach" with a x,y,z field next to it after clicking it this method gets called:
private async Task Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(new ManualTeachPage());
}
which then, as it should, creates the page but then for some reason decides to add a back button to it:
Debugging and Research
This behavior is not visible on Android which does not have a visible back button or navigation bar on this page but does have a backbutton on the Details-page as well.
I have used modal pages before but I have never seen this kind of behavior, I have tried using the Navigation property of the Application.Mainpage itself which resulted in the exact same result except for one case.
I thought it might have something to do with me switching out the Application.Mainpage at one point(there is a stack of tutorial pages the user has to go through), seems like calling the pushModalAsync one line AFTER setting the new mainpage then it DOES push the page as a modal page and performs like one (without a back button) but does not do so after this point.
No bug reports on Bugzilla about this either as far as I have seen, neither have I found anything on the internet about this particular problem.
Note that when clicking the back button on the teachPage it returns to the detailspage. When the teachPage gets pushed it does actually get pushed onto the ModalStack.
update 1
Checked again if the modal page which I was talking about was the only modal page on the modal Stack, it was. NavigationPage.SetHasBackButton(this, false); does not seem to work either as suggested by Diego Rafael Souza.
update 2
I thought I would temporarily disable the backbutton by using the onBackButtonPressed within the teachpage until I had found a solution. Turns out this doesn't work for UWP anymore, this method does not get called anymore on this page or any page for that matter. It does work for the Android Hardware button though.
update 3
I tried using:
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
AppViewBackButtonVisibility.Collapsed;
This does hide the backbutton on UWP but for some reason #if WINDOWS_UWP doesn't work at all. If I do this without the #if the program won't build for Android. No solution yet, not only this but when using this fix the other pages still had the onBackButtonPressed method disabled.
update 4
after updating to the newest version of xamarin forms the OnBackButtonPressed started working again. The backbutton still appears on the page but I now have disabled it.
Recreating the problem
I recreated the problem in this small test project:
https://www.dropbox.com/sh/6btsud3uvw503ee/AAAiaGb3TwhMrZMJb2j-rd36a?dl=0
In your function Button_Clicked() in your example, in page DetailPage, where you call your Modal, right after calling PushModalAsync(new TeachPage());, use:
NavigationPage.SetHasNavigationBar(this, false);
NavigationPage.SetHasBackButton(this, false);
My guess is when you tried using the above SetHasBackButton, you were doing it on the Modal itself, but the back button you were actually seeing came from your DetailPage.
Once you add this, the modal pops up, and the back button disappears. If you set a "Back" button on your modal in order to close it, you can easily get your NavBar and BackButton back in your DetailPage by adding in an OnAppearing() Function in your DetailPage code-behind like so:
protected override void OnAppearing()
{
base.OnAppearing(); // do the usual stuff OnAppearing does
NavigationPage.SetHasNavigationBar(this, true); //get your navbar back
NavigationPage.SetHasBackButton(this, true); //get your back button back
}
This question already has answers here:
Is making an asp:Button control invisible enough to be sure users won't be able to click it?
(3 answers)
Closed 7 years ago.
This is in ASP.NET web forms, I have a save button on a screen. When I load the page initially, under certain conditions, the save button is not rendered.
button1.visible = false
In my button clicked event, I have this
public void button1_click(Object sender, EventArgs e)
{
SaveData();
}
The only security preventing the user being from being saved is on whether the save button is rendered.
In MVC, it would be trivial to access the save button action method just by making a HTTP POST to the server with my own modified request.
In ASP.NET Web forms, I'm a little bit confused because it relies on the encrypted ViewState being posted back. Do I still need to add this security to the button1_click event too? If so, then can you tell me how a client can fire a postback to the server that would reach the button click event without the button being visible?
That is one of the common mistakes about ViewState - it DOES NOT serve your click events and many other things.
Each click on button (or checkbox if autopostback is enabled) raises an form submitting to server. And all info about what was clicked is included in form postback data as plain text. Then server parses this data and, as your button has IPostBackDataHandler implemented, it raises appropriate events like "button id has been clicked". So, you can actually change request body:
D__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPD...&ctl00%24_pdContent%24txtEmail=qwe%40aeqw.ry&ctl00%24_pdContent%24btnRtnUser=Login&__EVENTVALIDATION=%2FwEWDAL424aUAQLjtYbqCAKu8qTUCQLXm%2BfNAwKk2O%2B4DgK3ypStCAL6q%2BaACgKBnvb9CQLr8ey6CALxoZvDCALFt96ABgLMorjMAwoW3zW69NNlOXygWNnB6luGVWnk
Above you can see content of input with id=ctl00__pdContent_txtEmail and clicked login button with id=ctl00__pdContent_btnRtnUser.
More explanation about server events in WebForms here.
And please read more about ViewState here or even better explanation here.
https://stackoverflow.com/a/24064375/279911
According to this answer on another question, it looks like it is impossible to reach the button click event if the button is not rendered as long as you have the relevant security settings set.
Yes, setting a button's Visible property to false is enough to prevent
its Click and Command events from being raised, as long as you don't
turn off the default ASP.NET security features.
I am searching for techniques/ approaches to solve this problem:
dummy scenĂ¡rio:
In main page I have a button. when I click on it, it display a message: "are you sure?"
when I click ok... it redirect me for secondary page. Now if I want to go back, I click in back button of the browser... my intended behavior is to the application go to main page... but instead it show the alert box "are you sure"...
the same appens in forms...when I click back the application keep point me to the previous input instead of go to the previous page.
I suppose that is a dummy question... but for this context I don't have the knowledge for "googling" the right Keywords... so point me in the right direction it will be a huge Help;)
I have an ASP.NET web app that uses a single page, but makes some controls invisible and others visible throughout the workflow. It's a fairly simple application, which is why it just uses one page.
I'm not sure though how to reload the page when a user clicks a cancel button, or when they complete the workflow. Here's some details about the application workflow...
The page loads and displays a LoginTable control with a dropdown list with employee names, and a pinpad where a pin number is entered for the selected employee, and a login button.
On clicking the login button, a postback occurs where the pin is validated, and if valid, the Table control that holds most of the page contents (except the header) gets made invisible, and a new Table control gets made visible depending on the current status (clocked in or out).
At this point, either the ClockInTable or ClockOutTable control are visible, and the LoginTable control is invisible. The user can either click a Cancel button, or a Clock In / Out button (with some other things to select if clocking in, like work site and job).
What I want is, when the user either clicks the Cancel, Clock In or Clock Out buttons (after any other processing on postback), for the page to load again with a new session and showing the main LoginTable again just as if the user had restarted the browser and opened the page for the first time.
I've tried using Session.Abandon(), and then in the Global.asax Session_End event, I do
Response.Redirect("Login.aspx");
This doesn't work though; it still just reloads the same view of the page.
How do you reload the page (not refresh the page) as if it were the first access (i.e. not a postback)?
Also, I'm new to ASP.NET, so if I'm misunderstanding how a session works, please let me know.
Have you tried Response.Redirect()-ing the user to the same page? That should load the page as if it were a new one. It won't lose the session data though.
I'm not exactly sure you can do that the way you describe. However, what you can do is have a flag as a session variable. Call it say IsFirstComer. I'm not sure how the workflow of your system goes, but you can have it reset to true every time a new user logs in (hasn't started a workflow yet), or has exited a workflow (needs to start all over again), but as soon as te user has started the workflow you set it to false. Your controls behaviour can then be controlled through the value of IsFirstComer.
Have you write: if(!this.IsPostback) in the Page_Load method, after that try "Response.Redirect(page.aspx)" again.