Mono Support Custom Database fields. 

Viewed 105593 time(s), 19 post(s), 5/16/2011 3:45:20 PM - by shawndg
6/3/2011 2:53:06 PM
1871 Reputation 252 Total posts

tried another thing..

changed code behind too..

protected void BandNameValidate(object source, EventArgs arg)
{
this.vldCustomUserName.IsValid = false;
}

remove using ref..

still no go..

11
6/4/2011 8:25:51 AM
15993 Reputation 2214 Total posts

Hi,

to add your own custom validation don't use the existing (MonoX built-in) validator called "vldCustomUserName" but add your own. At the moment MonoX has below server side validation attached to the mentioned validator that's why it isn't working. 

void vldCustomUserName_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
    //no spaces and filesystem illegal characters are allowed in the username
    args.IsValid = args.Value.IndexOf(" ") == -1 && args.Value.IndexOfAny(System.IO.Path.GetInvalidPathChars()) == -1 && args.Value.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) == -1;
}

Please add the CustomValidator of your own and use args.IsValid to tell if the form is valid.

Regards

12
6/26/2011 12:18:37 AM
1871 Reputation 252 Total posts

Ok..

I got it sorta working..

now I am having some new issues..

I could not remove the custom validation.. if I did i got some odd error..
so instead I set it to disabled.. I was now able to get past that issue with spaces and invalid characters.

The new problem now is.. I am unable to stop MonoX using my own validator..
I added my own custom server side validation and when i try to set it to .isvalid = false// MonoX ignores it completely..
page still process and MonoX creates a user.. my validations are ignored.

Second..
I am working on building my own ext database info off of MonoX...
In order to do so I need MonoX to tell me what ID it just created and allow me a chance to insert my ext info into my own table..
Now I successfully implemented A Linqs system to handle my data and everything is working except..
I dont know how to grab the UserID GUID that MonoX just created during the user creation..
I need this to create my link so that I can join my ext table with MonoX to pull all the information

13
6/26/2011 5:57:25 AM
1871 Reputation 252 Total posts

Ok..

I want to add..

I got all the database stuff figured out.. Initial creation, and the edit page..
Now the only major issue is the inability to stop Monox from processing using the Isvalid args..

For any one needed some insight on profile saving and updating here it is..

saving.. example..

public override void CreateAccount(MembershipUser membershipUser)
  {
 
      Guid userId = SecurityUtility.GetUserId(membershipUser.UserName);         
       
       //add your database code here .. i used this method as way to pull the guid that stored
          //in the database that is
neededfor any type of database logic linking.
 
  }



updating..
this caused me some headache.. to get around it.. and figure out that monox has its own event handler

protected override void OnInit(EventArgs e)
{
    base.AccountUpdated += new MembershipModuleEvent(ctlMembership_AccountUpdated);
    base.OnInit(e);
}

     void ctlMembership_AccountUpdated(object sender, MembershipModuleEventArgs e)   
     {
 
         //get active Monox User Id
         Guid userId = SecurityUtility.GetUserId();
 
// add your database code here
 
     }

14
6/26/2011 7:33:17 AM
15993 Reputation 2214 Total posts

Hi,

  can you please take a look at the ValidationGroup of the WebPart, you need to be sure that ValidationGroup is the same.

Regards

15
6/27/2011 2:28:11 AM
1871 Reputation 252 Total posts

The ValidationGroup on all of the validators have no value ?

not sure what you mean by ValidationGroup of the web part.

Here is a copy of the webpart base code.

<%@ Control Language="C#" AutoEventWireup="true" Inherits="TheScene.Web.WebParts.RegisterBands" Codebehind="MembershipEditor.ascx.cs" %>
<%@ Register TagPrefix="MonoX" TagName="StyledButton" Src="/MonoX/controls/StyledButton.ascx" %>
<%@ Import Namespace="MonoSoftware.MonoX.Resources"%>
  
<div class="membership-module-container input-form" style="">
<div id="Div1" runat="server">
    <asp:ValidationSummary ID="validationSummary" CssClass="validation-summary" runat="server" />
    <asp:Label ID="ErrorMsg" runat="server" ForeColor="Red"></asp:Label>
</div>
  
<div class="register">
    <h2>
        <%= Page.User.Identity.IsAuthenticated ? DefaultResources.MembershipEditor_Title_UpdateAccount : DefaultResources.MembershipEditor_Title_CreateAccount %>
    </h2>
    <dl>
 
        <dd>
            <asp:Label ID="lblUserName" runat="server"></asp:Label>
            <asp:Label ID="lblUrlBandName" runat="server" Text="UrlBand"
                meta:resourcekey="BandUrl"></asp:Label>
            <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
        </dd>
 
        <dd>
            <asp:Label ID="lblBandName" runat="server" Text="BandName"
                meta:resourcekey="BandName"></asp:Label>
            <asp:TextBox ID="txtBandName" runat="server"></asp:TextBox>
   
            <asp:RequiredFieldValidator ID="vldRequiredUserName" runat="server"
                ControlToValidate="txtUserName" Text="!" SetFocusOnError="true"
                CssClass="validator ValidatorAdapter" Display="Dynamic"
                EnableClientScript="False" Enabled="False" />
 
            <asp:CustomValidator ID="vldCustomUserName" runat="server"
                ControlToValidate="txtUserName" ErrorMessage="Invalid Band Name" Text="!" SetFocusOnError="true"
                CssClass="validator ValidatorAdapter" Display="Dynamic" Enabled="False" />
 
                <asp:CustomValidator ID="vldBandName" runat="server"
                ControlToValidate="txtUserName" OnServerValidate="BandNameValidate"
                ErrorMessage="Invalid Band Name" Text="!" SetFocusOnError="true"
                CssClass="validator ValidatorAdapter" Display="Dynamic" />
        </dd>
 
 
        <dd>
            <asp:Label ID="lblGenre" runat="server" Text="Genre" meta:resourcekey="Genre"></asp:Label>
            <asp:DropDownList ID="DropGenre" runat="server"></asp:DropDownList>
        </dd>
     
 
        <dd>
            <asp:Label ID="lblFaceBook" runat="server" Text="FaceBook"
                meta:resourcekey="FaceBook"></asp:Label>
            <asp:Textbox ID="txtFaceBook" runat="server"></asp:Textbox>
        </dd>
     
        <dd>
            <asp:Label ID="lblTwitter" runat="server" Text="Twitter"
                meta:resourcekey="Twitter"></asp:Label>
            <asp:Textbox ID="txtTwitter" runat="server"></asp:Textbox>
        </dd>
 
        <dd>
            <label for="<%= txtPassword.ClientID %>"><%= DefaultResources.MembershipEditor_Password %></label>
            <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
            <asp:RequiredFieldValidator ID="vldRequiredPassword" runat="server" ControlToValidate="txtPassword" Text="!" SetFocusOnError="true" CssClass="validator ValidatorAdapter" Display="Dynamic" />
        </dd>
 
        <dd>
            <label for="<%= txtRepeatPassword.ClientID %>"><%= DefaultResources.MembershipEditor_RepeatPassword %></label>
            <asp:TextBox ID="txtRepeatPassword" runat="server" TextMode="Password"></asp:TextBox>
            <asp:RequiredFieldValidator ID="vldRequiredRepeatPassword" runat="server" ControlToValidate="txtRepeatPassword" Text="!" SetFocusOnError="true" CssClass="validator ValidatorAdapter" Display="Dynamic" />
            <asp:CompareValidator ID="vldCompareRepeatPassword" runat="server" ControlToValidate="txtRepeatPassword" Text="!" SetFocusOnError="true" ControlToCompare="txtPassword" Operator="Equal" CssClass="validator ValidatorAdapter" Display="Dynamic"></asp:CompareValidator>
        </dd>
 
        <dd>
            <label for="<%= txtEmail.ClientID %>"><%= DefaultResources.MembershipEditor_Email %></label>
            <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="vldRequiredEmail" runat="server" ControlToValidate="txtEmail" Text="!" SetFocusOnError="true" CssClass="validator ValidatorAdapter" Display="Dynamic" />
            <asp:RegularExpressionValidator ID="vldRegexEmail" runat="server" ControlToValidate="txtEmail" Text="!" SetFocusOnError="true" CssClass="validator ValidatorAdapter" Display="Dynamic" />
        </dd>
         
        <asp:PlaceHolder ID="plhRememberMe" runat="server">
            <dd>
                <label> </label>
                <asp:CheckBox ID="chkRememberMe" runat="server" style="float: left;" />
                <label style="margin-top: 2px; float: left;" for="<%= chkRememberMe.ClientID %>"><%= DefaultResources.MembershipEditor_RememberMe %></label>              
            </dd>
        </asp:PlaceHolder>
 
        <dd>
            <asp:Label ID="labInfo" runat="server"></asp:Label>
        </dd>
 
    </dl>
    <div class="input-form">
        <div class="button-holder" style="float: right;">
            <MonoX:StyledButton ID="btnCreateAccount" runat="server" CssClass="CssFormButton"></MonoX:StyledButton>
            <MonoX:StyledButton ID="btnUpdateAccount" runat="server" CssClass="CssFormButton"></MonoX:StyledButton>
        </div>
    </div>
</div>  
</div>


Any idea whats wrong ??

16
6/27/2011 10:53:56 AM
15993 Reputation 2214 Total posts

Hi,

mark-up looks ok to me, can you please post the code behind so we can take a look at the BandNameValidate implementation.

Regards

17
6/27/2011 3:53:22 PM
1871 Reputation 252 Total posts

its this simple..


protected void BandNameValidate(object source, ServerValidateEventArgs args)
{
txtUserName.Text = txtUserName.Text.Replace(" ", "");
args.IsValid = false; //should invalidate the form but it does not..
}

Im just trying to invalidate evrything at the moment just to make sure the isvalid is stopping monox..

18
6/28/2011 8:37:15 AM
15993 Reputation 2214 Total posts

Hi,

I have reproduced the issue you are having, and you did everything ok except the validation group that I have mentioned. As you have inherited from MonoSoftware.MonoX.ModuleGallery.MembershipEditor which is a MonoX WebPart it has dinamically generated validation group value (It has to be dinamically generated because user can add more than one Membership editor to the Web part zone - Page, and every membership editor has to operate in a separate validation group). So this is the code you have to add to your Membership editor

protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);
    vldBandName.ValidationGroup = this.ValidationGroup;
}


Regards

19
1 2
This is a demo site for MonoX. Please visit Mono Software for more info.