asp:CreateUserWizard Redirecting After Complete - c#

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.

Related

MVC - Catching a navigation request on the site controller before the LayOut controller

At my company we are discussing wether or not to got and make our next web app in MVC.
I have been charged to figure out some basic stuff which could stop us dead in our tracks, and so have spend some time figureing out the MVC platform as best i could.
There is however one thing im wondering, is it possible, and if so how - to have a menu made on the _LayOut page/controller, which when a user presses a menu navigation i am able to catch on the specfic page before it goes to the layout controller?
UPDATED I forgot to mention that i want to be able to save a form depending on what site i am on. So i may have 10 pages with different forms and depending on which one of these i am on, i have to save the form on that page using the same link in my menu.
My explaning might be abit off so ill quickly describe the scenario and maybe there is another way of doing this.
The user is filling out alot of data on the page, they then press the navigation menu to go to a new page, i want to save the entered data before navigating to the next page for them.
Sorry for my bad english it is not my primary language.
Thanks in advance for any help.
A way to do what you're looking for is to attach a client-side event handler which submits the data before navigating to a new page. It would look something like this:
$(".navigation a").click(function (event) {
// Get form data, process it and POST/PUT/DELETE
});
If you're supporting modern browsers then you can subscribe to the input event of your form and attach yourself on the before unload if anything in your form has changed since the window was loaded as suggested in one of the comments. If you need to support older browsers as well subscribe to the change event of the input fields in the form in order to attach the handler for beforeunload.
form.oninput = function () {
window.onbeforeunload = submitFormData;
};
function submitFormData() {
// Gather and submit your data
}

C# WebBrowser turn off jquery popups

I have an application that uses WebBrowser control to navigate from page to page, on some pages I get a leaving popup asking me if that's what I want to do.. this stops the whole further execution until I press "Leave" or "Stay".. How can I disable them?
What I've tried so far were these actions:
a) setting window.onbeforeunload = null;
b) setting alert, confirm, prompt to an empty function
c) settin suppressErrorMessages to true
but even so, I still get the nasty message in the end.
I mostly relied on this answer:
How to update DOM content inside WebBrowser Control in C#?
But so far without a success.
The alerts seem to be jQuery alerts because they have custom texts (instead of OK Cancel, they have Stay Leave)..
Any help hugely appreciated!!
The webbrowser control uses IE internally and IE has a prompt if you've filled out a form asking you if you really want to leave the page (thereby losing the content you've filled out) perhaps that's what you're seeing?
i'm just shooting from the hip here but you could try clearing all inputs before navigating.

How to stop errors from showing on web pages, show on pop up instead?

i am developing this app which is going to be a template in my organization, but there is a problem i need to solve. I want to show errors on an AjaxControlTookit's modalpop and never let it show that ugly yellow text on the browser with stacktrace.
WHERE should i intercept and WHAT should i intercept for this to work?
Is there an lifecycle event i can use that happens before rendering but after the page is itself contructed (and thus the error has happened?) at that event, will i have the page controls ready? Assuming i have a masterpage and the modalpopup will be there, could i do this general error handling in the masterpage?
Is this something i need to use global.asax? (i have never used it, but with a name like that and the events it has, i can figure what it does)
Is this something doable even? could i catch every exception, even browser errors that happened related to my pages?
Edit:
My problem isn't really with what the user sees, is that i don't want the browser to display the stack trace and the yellow error page, destroying anything the user has done so far.
I want to create a nice and clean user experience and if the user can recover from whatever issue is causing the exception i want them to have the option, which include not destroying the page they had before the post-back. Is that understandable or i am unable to explain this any better?
You could easily do this using javaScript:
window.onerror = function(msg, url, linenumber) {
alert('Error message: '+msg+'\nURL: '+url+'\nLine Number: '+linenumber);
return true;
}
http://www.javascriptkit.com/javatutors/error2.shtml
Generally speaking, here is a link on how to handle errors (including global errors) in ASP.NET:
How to: Display Safe Error Messages
Then with regards to the modalpopup, in the samples mentioned in the link, the user was redirected to some other error page. You can pass the error messages to that error page and then display the modelpopup on that error page.

Browser Back Button issue in asp.net

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.

How to make the 'Are you sure you want to navigate away from this page' warning message in browser?

I have a web page that contains a textbox and a submit button. When the user edits the text in the textbox and clicks another link (not the submit button) how do I display the 'Are you sure you want to navigate away from this page' popup message?
I have researched this on the net and found a few javascript examples. Is this the only way you can do this? If not, what is the best way to do it?
This is one of the multiple ways to achieve the same thing
function goodbye(e) {
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}
window.onbeforeunload=goodbye;
got it from here open js
Only the unload() event will work on JS. You can't manage it on the server.
Check out the answer to this other question on SO, it is very similar to your question
How to show the "Are you sure you want to navigate away from this page?" when changes committed?
Simple solution
window.onbeforeunload = confirmExit;
function confirmExit() {
return "Are you sure you want to leave this page?";
}
4guysFromRolla.com - Prompting a user to Save when Leaving a Page
You cannot use the onbeforeunload window method as it gets triggered by multiple ways like back and forth browser navigation links, refreshing the page, closing of the page, clicking on the links.
What i feel you have to bind the link tag for which you want display the navigation away message and then use the function for the status message display
window.addEvent('domready',function(){
$$('a').addEvent('click', function(e) {
//leaving(); function u wrote for displaying message
});
});
function leaving(e) {
if(!e)
e = window.event;
// return code for the displaying message
}
If you want to do this in a way that guarantees it will work on almost all browsers, use the JQuery library. The following describes the unload event.
http://www.w3schools.com/jquery/event_unload.asp
It's exactly for purposes like yours.
Just to elaborate a little, you would have to download the jquery js library and reference it in your project/page, but you'll probably want to do that eventually anyway.
If you want to control this from the server side, you can dynamically emit the jquery call in the OnPreRender.
Look into Jquery's .beforeunload property. Here is an example:
$(window).bind('beforeunload', function(){ return 'Click OK to exit'; });
Please note, beforeunload canot prevent a page from unloading or redirect it to another page for obvious reasons; it would be too easy to abuse. Also if you just want to run a function before unloading, try the following:
$(window).unload(function(){ alert('Bye.'); });
Finally, don't forget to referrence jQuery in your head tag by using:
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
The above gets you the latest version from the internet and saves you the trouble to download it, and of course you can do so optionally, but I am just trying to get your thing to work asap.
Oh, I also found an example for you. Click here to see a page that calls a function before it closes. Hope this helps bud.
I was able to get this to work with Andrei G's answer. I would add on that to get it to work in Chrome, add this to the end of his goodbye function:
return "";

Categories

Resources