Is there any way to when you click submit on a form, as each method call within the form submit post method completes, a check box checks off to show the user progress of the next page being loaded?
No. I think the best you could do is to disable the form and make ajax calls to each "progress" action that you want the user to be aware of. Each ajax call could then update the page with whatever indicators you want. The resulting flow would look something like this:
User clicks on fake "submit" button.
Page is disabled
Ajax call to "progress" action method 1 - Update page with indicator
Ajax call to "progress" action method 2 - Update page with indicator
Ajax call to load new page.
Display new page to user
Related
I am trying to implement login and logout in asp.net(web forms). In my web form I have two pages namely Default and Main. From Default page when I login with username and password it redirects to the Main page. When I press back button it directly redirects to the default page. For this I copied javascript code to my default page
<script type = "text/javascript" >
function preventBack() { window.history.forward(); }
setTimeout("preventBack()", 0);
window.onunload = function () { null };
source from stackoverflow question
After login when I click on back button in my browser(chrome) first it shows the Default page and then it shows the Main page. i.e page blinks when I click the back button.
It shows main page successfully with the issue.
What should I implement to stop showing the Default page when I click on back button
Update:
<script type = "text/javascript" >
history.pushState(null, null, 'Default.aspx');
window.addEventListener('popstate', function (event) {
history.pushState(null, null, 'Default.aspx');
});
</script>
I placed this code in default page
There is one important thing that you ought to know here.
One cannot disable the browser back button functionality only thing that can be done is prevent it.
You can't, in anyway diasble that button. What you can however do, is to put some logic and prevent that button from doing what it is meant to do.
Now for the script that you have shown, it should serve fine and the other thing to try here is to put a mediator page between your default and main page. So when you login, the control will flow to mediator page and it will then redirect to main page. Now when the user presses back button on the main page, the control will flow to mediator page which will again redirect the user to his main page.
The effect will be the same as your script, but putting a page can help you write Session handling code and some server side checks if you want.
But one thing is sure, the browser back button will be as it is.
Hope this helps.
As Matt said you can't disagree the back behaviour. However you can check if the user is logged in and redirect them to the main page easily.
All you need to do is, on the default page check if the user is logged in, if they are then redirect them to the main page, this way even if the user clicks back, they will be taken back to the main page. And also the can go to the Default page after logging out.
Another way could be using location.replace("...."), which replace the existing document and user can't "go back" using back button as the page doesn't exist in the url history.
Src: https://developer.mozilla.org/en-US/docs/Web/API/Location/replace
EDIT
Figured it out.. $.ajaxSetup({ cache: false }); wasn't working because i had data-ajax set to turned off on the form and therefore i wasn't able to set no cache ajax on it.. just for completeness if anybody knows how to get this done WHILE dada-ajax is set to false then please post so here
Something else that I just tried and it worked was to simply add data-ajax="false" to any link that you want a page refresh on. Meaning that if I have data-ajax="false" on a link it will always refresh the page before showing it!
For example the link I had a problem with was
Add a new weekly update
and the problem was that for some reason that page was caching and always showing the cached page.. So one of the easy fixes was to add data-ajax="false" to it and that forced a reload of the page everytime
Add a new weekly update
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Question:
I have a options menu which brings up a form which also has a cancel and submit button.
Once the form is submitted there is certain validation that runs and if something is missing it returns to the form with some validation text.
Now if I click the cancel button at anytime i should be brought back to the options menu and if I click on the same button that brings up the form i should see a brand new clean form and this works fine if I do it before the validation.
The problem is that if I submit a non valid form which returns with the error validation messages and THEN press cancel it seems that the page becomes cached or something similar because from that point on anytime I click on the form options menu button the same form shows up each with the validation errors and data. I put a break point in the method that returns the form View() and they are never hit so for some reason it skips the entire method which creates a new form and somehow just shows the old page.
The cancel button is the following
Cancel
Does anybody know what is happening? is it being cached somehow when it returns to the same page with the validation errors??
** EDIT **
I Tried adding [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")] in front of the controller by to no avail..
I also now added
$.ajaxSetup({ cache: false });
to the top of my $(document).ready(function () but that also does not seem to be doing anything, do I just put it there or do I have to call it somehow?
I checked System.Web.HttpContext.Current.Cache and the page doesn't show up there.
Have you tried setting the output cache options on the controller action like
[OutputCache(Duration=600,VaryByParam="id")]
You might also want to try making sure jquery is not caching the request as well. You can globally turn off jquery ajax caching using the information here: How to set cache: false in jQuery.get call
You can try using $.mobile.changePage() to transition to the page, it allows you to set some options, one of which is reloadPage.
reloadPage (boolean, default: false) Forces a reload of a page, even if it is already in the DOM of the page container. Used only when
the 'to' argument of changePage() is a URL.
Source: http://jquerymobile.com/demos/1.1.1/docs/api/methods.html
You could work this into your link with something like:
<script>
function changeMyPage(url) {
$.mobile.changePage(url, { reloadPage : true });
}
</script>
Cancel
jquery Mobile pulls multiple pseudo-pages into the DOM at one time and normally deletes (.removes()) a pseudo-page after you've navigated away from it. It however sounds like that's not happening so you may need to use my above code (or something similar) to force a refresh of the page.
You need to clear your ModelState before hand.
This should work:
if (ModelState.IsValid)
{
//saving
if (result > 0)
{
**ModelState.Clear();**
return View(new CategoryViewModel());
}
}
How to Clear model after submit the data in database in MVC3
The main idea is to replicate what we see on the Banks or American Express sites, where a MODAL Popup appears to they tell us that the session "is going" to expire.
To this, I wanted to add an "Auto-Close" Popup event that will happen after XX seconds and then I will want to call a button event Onclick to "auto save" the current work, before redirecting the user to the Logout page.
So mainly I would like to know what's the best way to do the following:
1) Display a MODAL Message after let's say 1 minute (for testing purposes). This could be a DIV appearing on top of the current page, or a Dialog Message Box both MODAL.
2) Display a message and also a Reverse Timer, something like "Please save your work before the session expires"
3) Auto Close (or hide) that Message dialog after XX seconds
4) Call a button onclick event.
BackEnd is ASP.NET using C#
Something like this will get you started:
setTimeout(WarnTheUser,10000);//fires after 10 seconds
function WarnTheUser()
{
document.getElementById('warningDiv').innerHTML="<H1>This page will auto save in 1 minute</H1>"; //or whatever
setTimeout(saveData,60000);
}
function saveData()
{
form.submit();//adjust accordingly
}
jsfiddle.
I have an Index.aspx with a button inside which that button will call a controller, doing some logic and returning to a PartialView control - let's named it PopUpPartialView.ascx (as a popup). So to make it clear, the popup windows(PopUpPartialView) actually stays ON the top of Index.aspx when user clicks on the button.
In PopUpPartialView.ascx, there is another button, that returns say a GenerateList and now the problem is - how do I pass the thing back to the same popup windows in PopUpPartialView.ascx on the top of Index.aspx as it was before? How should my controller codes look like?
Here's what I have on the return:
return PartialView("PopUpPartialView", GenerateList);
this clearly NOT working as what I want, because it doesn't point back to Index page. I was thinking perhaps to use ajax so that I could stay on that popup ascx page. Confused~~ Someone please guide me.
Thanks.
My advice is to use a plugin which handles all the popup plumbing for you.
My poison of choice is jqModal.
It's very easy to work with - essentially a hidden container on the page, and you can load contents in there either on the initial render, or on a click event via AJAX.
So in your example, you could handle the button event click, show the dialog and load the contents of your partial view into the hidden container.
I have a button called btnSubmit where i set the Form action attribute to a URL like so.
Protected Sub btnSubmit_Click(ByVa....
Form.Attributes.Add("action", "http://now.eloqua.com/e/f2.aspx")
End Sub
This does work but for some reason it only works after I clicked the button the second time. Why is this and how can i fix this?
I am using ASP.NET 3.5 with VB.NET(C# code is also fine)
What I actually want to do it do some code on the submit and then as soons as everything is complete, then set the form action attribute where it must send the form data to another location at that URL.
Thanks in advance!
Fabian is right.
Your code executes on the serverside, after the first submit.
To do what you want, you'll need to emit some javascript using the scriptmanager, which executes in the client, since it will all have to happen before the submit happens in the first place.
Use Page.ClientScript.RegisterClientScriptBlock() to emit a script block with a suitable function which does your stuff, then sets the form's action attribute. Call that function from the button using the OnClientClick attribute.
It doesn't work the first time because the form on which the attributes are added is already rendered.
The first time you click the button, it sets the form attribute, the second time you click it, it's submitting the form that you edited the first time round...
You might want to set the form attribute at some other point in the page lifecycle.
If you need to retain the POST data between pages you might want to use Server.Tranfer. See here for a most excellent explanation: Using asp.net, how do I redirect a user and change the POST data at the same time?