I have registration form, suppose there are 5 fields, and all are required i.e. mandatory.
My problem is that when user login & fill 2 fields of that registration form & click browser back button, then I want to restrict user to same form & Show requiredField Validator messages of incomplete fields. So How can I fire Validation on browser back button & restrict user on same form.
You cannot affect browser behavior when the user clicks the Back button.
The correct solution is to check right after user have been login, if he has complete the registration entries on database, and if not you redirect him to fill that data.
From your comments, to alert them a solution is to capture the onbeforeunload and check there if they have fill out everything or not, show your message.
Simple example, you just need here to place your conditions.
window.onbeforeunload = function() {
return 'You have unsaved changes!';
}
You can't disable the back button (see the other answers and their comments).
What you can do is check on every page whether the user is logged in. If not, redirect him to your login page. This way the user can't access the site without logging in, which I guess is what your client is really after.
Related
I am using the PasswordRecovery Control in my ASP.NET WebForms Application (C#), now the thing is, When we are using PasswordRecovery Control, we are forced to use Wizard Control, which means, if the user enters username correctly, it will then hide textbox and display success message (or whatever you put in SuccessTemplate).
Now, the issue is by this way, when Unauthorized user, tries to access the application, they can try this control to get the actual username from the application (security risk). So, if they try the wrong username, they will get the "UserNameFailureText" and if they will enter the proper username, they will see the next template (SuccessTemplate) which will show a success message (By this way, they can get that the entered username is available in the system or not), so I want to remove the wizard structure, in all scenario, the textbox with a username will stay on the screen, and no matter what user enters, he will see a generic message "if you have entered the correct username, you will receive an email" Like that.
If anyone has any idea whether it's possible in PasswordRecovery control, or should I have to build a custom Page?
PS: I have tried removing SuccessTemplate from the page, it will automatically take the default success template.
I don't see why you can't just create a page from scratch? All that text box will do is check if the user exists, send them the email, and display your message. There not a whole lot of reasons thus to use the built-in template.
So, a simple button re-set password can run some code behind, send the re-set email, and set a label or text box, or even some "div" as visible = true to display your message. You don't mention or note that authentication provider you are using - but given the built in templates - then that suggests FBA, and thus the tables that drive the site and hold user + passwords should be fully available to your code behind.
On the other hand, you might have to add some kind of password re-set table, and say include a GUID generated ID, and the datetime. That way, the link you send in the email is specific to the one user - and has a limited time before that link expires.
Or I suppose the link in the email just directs them to the new password page - but I tend to toss in a GUID that is checked against that new re-set table. With the guid, then when they click on their email link, you can display their name, and only prompt for the new password. The email link simply includes that GUID as a parameter, and you pull that one row from the re-set table to get who is about to re-set their password.
I am trying to integrate Stripe with my website with "Simple" checkout as described at https://stripe.com/docs/checkout . I have created a summary page on which I have added script tag. This shows the Pay With Card and it works fine.
However, I need a "Cancel" or "Back" button on this summary page so as to give user chance to go back to previous page or cancel online booking. But even when this other button is clicked, the Payment pop-up is opened and it is not raising the back button event.
What am I missing? Why even other buttons are hijacked by Stripe JS. Please help.
Simple Checkout allows the user to enter their credit card, then creates a token, then immediately submits the <form></form> which encloses it. If you need more customizability than that, you'll need to use the Custom Checkout integration.
With the Custom integration, the user is presented with Checkout, Stripe generates a token, then it is up to you to decide what to do next --- you could write JS in the token creation callback to append a hidden field with the token and then immediately submit the form, or you could land the user back on your summary page and wait for the user to give an additional confirmation before submitting your form, or 'go back.'
var handler = StripeCheckout.configure({
key: 'pk_test_xxxyyyyzz',
token: function(token) {
// You can access the token ID with `token.id`.
// Do something with that token (append a hidden input + submit the form?)
}
});
Currently I'm in say Page A. The URL is http://localhost:22507/PageA.aspx. From there select a dropdown value. Now the same page shows some extra data and an edit button along with the dropdown. Page URL is still http://localhost:22507/PageA.aspx. When I click the Edit button its redirected to another page Page B. And the present URL is http://localhost:22507/PageB.aspx?qstr=6EysKHDt1+a/m8SQcruQOCVgWF+9+PCfmydyeX5wbKU=
While clicking the Back button in the Page B, it directly goes to the first state. ie, I've to again select the drop down, click edit etc.
How can I go back to the just previous state(Page A with data and Edit button) after clicking Back button?
Now I use Response.Redirect("PageA.aspx", false); for redirecting
When changing the selected list item, use pushState to update the browser address bar and history to record the change of state. E.g instead of the address bar still displaying /PageA.aspx, it could instead show /PageA.aspx?selected=1.
If you then use the back button from PageB.aspx?qstr=6EysKHDt1+a/m8SQcruQOCVgWF+9+PCfmydyeX5wbKU=, pressing back will return you to PageA.aspx?selected=1. You can then parse the query string to determine the correct state to display.
Mozilla provides documentation on pushState here: https://developer.mozilla.org/en-US/docs/Web/API/History_API.
Note that for older browsers there are some compatibility issues. A clunky old method that would work would be to reload the page with a query string when the dropdown is changed, allowing the back button to work in much the same way. An alternative that avoids reloading the page may be to update a cookie with a flag indicating the state. On loading the page, check for the cookie and flag. However, then you would need to consider expiry of the cookie (ie what if they didn't press back but instead navigated to pageA again through some other means, would loading the saved state still be acceptable?).
I have a form to edit employee information. If the user wishes to enter a new e-mail address for the selected employee, there is a textbox and a button that says "Add Email Address." Very simple, you enter the e-mail address, click Add Email Address. It postsback and that button's event handler executes the INSERT to the database.
The problem:
If you press F5 to refresh the page after that postback, it causes the same postback to occur, even if the textbox is blank. In other words, for every time you hit F5, the actions in the event handler for that Add Email Address button occur again. If I hit F5 ten times, the same e-mail address shows up in the database ten times.
One suggestion I found said, "just re-direct to the same page after you apply your changes." The reason this is not ideal in our case is that it's a rather lengthy form of employee data --- if the user makes a bunch of changes to the overall form (such as FirstName, LastName, etc.), then makes an e-mail addition before applying the changes elsewhere, those changes elsewhere would be lost if we re-directed to the same page.
The very long winded solution I can think of is, capture all of the data in ViewState, carry it across the re-direct to the same page, then use a query string in the URL to determine if we want to fill in the data from ViewState. Before I embark on that path, I'm hoping that instead of that, there is some method I just don't know that says like, PostbackButDontRetainPostbackData() (wishful thinking, I know).
In the handler for that Add Email Address button check if the email already exists in the database. If it does, do not add the email again and display an appropriate message to the user. Usually forms have a reserved area like a hidden div for this purpose so in case anything goes wrong the div will be populated with error messages and displayed to the user.
Also, it would help to display a confirmation message to the user when their data is successfully received and processed.
UPDATE
If you don't like to show any messages to the user, simply do nothing after you find out that the email already exists in the database. e.g.:
public void AddEmailToDB(string email)
{
// first find out if the email already exists in the database
bool isDuplicate = ...;
// if it does, simply return and do nothing
if(isDuplicate) return;
// if control reaches here then the email is not
// a duplicate and you can do your normal processing
}
UPDATE II
If you don't want the browsers to show a messagebox everytime a user presses F5 after a postback, you can do a partial postback using AJAX by wrapping your email textbox and add button in an UpdatePanel, it's very easy to use.
I have an asp registration page using a custom asp:CreateUserWizard.
Once the registration is completed successfully (RegisterUser_CreatedUser for example) I want to redirect the user to another page, be it a welcome screen, etc... (using Response.Redirect(URL); I guess), but I also want to, some how, popup a new window with the login page.
Is it possible to popup a screen from an external url using this method, or is there another way I should go about it?
I did try creating a custom button which calls this js function for registration:
function redirectAfterRegister() {
Page_ClientValidate();
if (Page_IsValid) {
window.open('/Account/Login.aspx?UserCreated=True');
$('#CreateUserButton').click();
}
return false;
}
This popup works because its called off a click, but the problem with this is the popup is always called even if the creation of the user was unsuccessful - which is wrong.
Any help is highly appreciated.
The problem is that popups only work when a user actually clicks in external sites. This prevents spammers from popping up ads all the time. Once another function is called after the click it is considered unfriendly and therefore to allowed externally.
I think it best to let the user know the registration was successful and give them navigation options from there. If anything, at least its user friendly that way, without confusion.
The asp:CompleteWizardStep can be used to redirect after successful registration, and provide extra navigation where needed.
Good Luck, and let me know if you find an alternate solution.
Why not use the CreateUserWizard.ContinueDestinationPageUrl property to go to your welcome page. You can then place your javascript to open a new window in the onload event of the Body element.