Hook up to code to stay on page

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
1/22/2014 2:24:12 PM
Gravatar
Total Posts 22

Hook up to code to stay on page

I know there is some code in the mojoPortal features to warn a user that there are unsaved changes when they navigate off a page.  Can I hook up to this code when developing my own features and, if so, how or where's the best place to look to work it out.

Thanks for your help.

1/22/2014 3:18:27 PM
Gravatar
Total Posts 18439

Re: Hook up to code to stay on page

There is a javascript function included in the core of mojoPortal that you can call from your own custom javascript to hookup the prompt, you have to pass in the message you want for the prompt. We call it from the onchange event in the editor after checking the editor IsDirty function to make sure content really did change since many things can fire the onchange event in the editor even without real changes.

If you are trying to make the prompt happen for an editor in your custom feature you don't have to write javascript since we already have it built in for the editor, just add this line of server side code in page load:

ScriptConfig.EnableExitPromptForUnsavedContent = true;

if you need to make the prompt happen for other things besides the editor then you need to write your own javascript:

hookupGoodbyePrompt("your prompt message");

Then you have to remember that the save button in your feature that does postback needs to unhook the prompt otherwise it can't postback. You can add code to your button from server side:

using mojoPortal.Web.Framework;

UIHelper.AddClearPageExitCode(btnSave); //unhook the prompt

where btnSave is the server side id of your button.

Hope that helps,

Joe

1/27/2014 5:34:29 AM
Gravatar
Total Posts 22

Re: Hook up to code to stay on page

Thank you - that's great.  I am using a DevExpress grid in the feature.  In case it's useful for someone else, here's how I implemented it.

In the Page_Load event for the feature I set ScriptConfig.EnableExitPromptForUnsavedContent = true;

On the grid's AfterPerformCallback event server side I check the call back event name and, if it is ADDNEWROW or STARTEDIT I set a custom JS property to true, otherwise I set it to false.

In the grid's client side EndCallback event I check the custom JS property - if true I run the hookupGoodbyePrompt script, if it's false I run the unHookGoodbyePrompt script.

 

 

You must sign in to post in the forums. This thread is closed to new posts.