Custom Validation on Custom User Profile Properties

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.
4/14/2011 8:04:38 AM
Gravatar
Total Posts 4

Custom Validation on Custom User Profile Properties

I've setup some custom User Profile Properties in CustomProfile.config, and I'd like to be able to call code in one of my libraries to validate the Custom Properties rather than just having a Regex.  Is this possible?  I'd obviously like to avoid hooking a CustomValidator into Register.aspx because that would fork the code (and may not be possible with the Custom Properties anyway).  Any suggestions?

 

Thanks in advance,

Paul

 

4/14/2011 8:15:22 AM
Gravatar
Total Posts 18439

Re: Custom Validation on Custom User Profile Properties

Hi Paul,

I think you could do it if you implement your custom setting as a UserControl.ascx that implements ISettingControl

You could then use whatever custom validators you want inside the usercontrol, just set the ValidationGroup="profile"

Hope it helps,

Joe

4/14/2011 8:19:41 AM
Gravatar
Total Posts 4

Re: Custom Validation on Custom User Profile Properties

If I do it that way, aren't I breaking the spirit of the User Profile extension mechanism that you built-in?  I mean, in the CustomProfile.config I can't specify a control to use, so I'd have to do that in Register.aspx, which forks that code.  Or am I missing something elementary?  BTW - I did try to do this in my custom MembershipProvider (which extends mojoMembershipProvider), but the custom SiteUser properties are not yet available when Provider.CreateUser(...) is called.  Also, I've implemented a custom UserRegisteredHandler to do some custom things for me, but here it is too late to validate a reject a user.

 

Paul

 

4/14/2011 8:28:45 AM
Gravatar
Total Posts 18439

Re: Custom Validation on Custom User Profile Properties

No, the custom profile system supports use of user controls that implement ISettingControl

If you look in the mojoProfile.config file for example you will see that the TimeZone is implemented as ISettingControl and is configured like this:

<add name="TimeZoneId"
    type=""
        iSettingControlSrc="~/Controls/TimeZoneIdSetting.ascx"
        resourceFile="ProfileResource"
    labelResourceKey="TimeOffsetLabel"
        defaultValue=""
    requiredForRegistration="true"
    regexValidationExpression=""
    regexValidationErrorResourceKey=""
    includeHelpLink="false"
      />

you could study the source code of the control it points to as an example of ISettingControl, it is a very simple interface, this example wraps a dropdown list but you could wrap a textbox if you just have a string value that you want to have custom validation against. When using an ISettingControl you should set the type to empty string as shown and the iSettingControlSrc points to your control which can be located in any folder but probably best to keep yours in a custom folder rather than mingle them in with built in controls. 

Hope it helps,

Joe

4/14/2011 9:48:44 AM
Gravatar
Total Posts 4

Re: Custom Validation on Custom User Profile Properties

Thanks Joe, I'll take a look!

4/14/2011 10:38:00 AM
Gravatar
Total Posts 4

Re: Custom Validation on Custom User Profile Properties

One thing I found is that the CustomControl has to be under mojoPortal.Web.Controls, it won't let me load a control in an external assembly.

4/14/2011 11:40:28 AM
Gravatar
Total Posts 18439

Re: Custom Validation on Custom User Profile Properties

That is not true, if your usercontrol.ascx has code behind it should be compiled into a dll and it should be in the /bin folder as a dll.

Basically you implement it in a custom Web Application project to keep your code separate, then you use a post build event to copy your .ascx file and the dll up to the Web project. You can see examples of post build events by right clicking the mojoPortal.Features.UI project (or WebStore.UI), choose properties then click on the Build Events tab.

You should not be adding code nor controls into the mojoPortal projects all custom code should be in your own projects. It is the same model as we used for the mojoPortal.Features (or WebStore) set of projects they depend on mojoPortal core but mojoPortal core does not depend on them.

Hope it helps,

Joe

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