Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Evan 344 posts 99 karma points
    Aug 05, 2009 @ 16:01
    Evan
    0

    Registering a new member via website user control error

    I am setting up a mailing list and need to have email address and names stored in the members section (with a member being created automatically).  I have written a register user control that should work but I am getting an error. Any help would be greatly appreciated... I am basing this off of some code from Tim:

    ASCX Code:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Register.ascx.cs" Inherits="UmbracoCreateMember.Register" %>
    <asp:Label ID="lblName" runat="server" Text="Name:"></asp:Label><asp:TextBox ID="txtName"
        runat="server"></asp:TextBox><br />
    <asp:Label ID="lblEmail" runat="server" Text="Email:"></asp:Label><asp:TextBox ID="txtEmail"
        runat="server"></asp:TextBox><br />  
    <asp:Button ID="btnRegister" runat="server" Text="Register"
        onclick="btnRegister_Click" />

     

    Error:

    Error creating usercontrol (/usercontrols/website/register.ascx)
    Could not load type 'UmbracoCreateMember.Register'.
      at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)
      at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPath virtualPath)
      at System.Web.UI.TemplateParser.ParseInternal()
      at System.Web.UI.TemplateParser.Parse()
      at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType()
      at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)
      at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()
      at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
      at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
      at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
      at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
      at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath)
      at umbraco.macro.loadUserControl(String fileName, Hashtable attributes, Hashtable pageElements)
  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 05, 2009 @ 16:31
    Sebastiaan Janssen
    0

    Make sure that the namespace in your Register.ascx.cs is correct.

    In Visual Studio you can go into the class explorer to see if the class UmbracoCreateMember.Register actually exists.

  • Evan 344 posts 99 karma points
    Aug 05, 2009 @ 16:36
    Evan
    0

    That seems to be the problem, there is no umbracocreatemember.register file in the class view.  This is all adapted from Tim's blog post here, how can I get this to work?

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 05, 2009 @ 16:44
    Peter Dijksterhuis
    0

    Did you compile the project in Visual Studio?

    If you look at the Register.ascx.cs file, there's the class that you need, so it does exist.

    Looks like you didn't copy the dll to the bin-folder.

    HTH,

    Peter

  • Evan 344 posts 99 karma points
    Aug 05, 2009 @ 16:58
    Evan
    0

    What dll do I need to copy over?

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 05, 2009 @ 16:59
    Peter Dijksterhuis
    0

    UmbracoCreateMember.dll

  • Evan 344 posts 99 karma points
    Aug 05, 2009 @ 17:00
    Evan
    0

    I dont know where that is...basically what I did was create a usercontrol in umbraco and added the ascx and the codebehind, I did not build anything in VS....What do I need to do to get this to work...

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 05, 2009 @ 17:05
    Sebastiaan Janssen
    0

    I would actually recommend to look into the Microsoft member provider (as Umbraco 4.0.1 supports it). You can very easily create members using that method.

    I don't currently have sample code for you, but it doesn't require any work in VS. Give Google a try! :)

  • Evan 344 posts 99 karma points
    Aug 05, 2009 @ 17:26
    Evan
    0

    Ok I have built the solution and copied over the DLL file and I still get the same error....This is my first user control creation so please bear with me....I built the project in VS, pulled the dll over and copied over the ascx code as well as the code behind and I am still getting the same error...

  • Fredrik Sewén 39 posts 106 karma points
    Aug 05, 2009 @ 17:33
    Fredrik Sewén
    100

    I'm just guessing here, but you downloaded Tim's sample project and copied the full text in Register.ascx and Register.ascx.cs to your own user controls, right?

    If that is what you did, I suggest you start over.

    1) Delete your user control and create a new one.

    2) In cs-file, just copy the two parts that Tim describes.

     

    using umbraco.cms.businesslogic.member;
    using umbraco.cms.businesslogic.propertytype;

    And

    protected

     

    void btnRegister_Click(object sender, EventArgs e)

    {

     

    if (Member.GetMemberFromEmail(txtEmail.Text) == null)

    {

    MemberType demoMemberType =

    new MemberType(1040); //id of membertype 'demo'

    Member newMember = Member.MakeNew(txtName.Text, demoMemberType,

    new umbraco.BusinessLogic.User(0));

    newMember.Email = txtEmail.Text;

    newMember.Password = txtPassword.Text;

    newMember.LoginName = txtUsername.Text;

    newMember.getProperty(

    "address").Value = txtAddress.Text; //set value of property with alias 'address'

    newMember.getProperty(

    "city").Value = txtCity.Text; //set value of property with alias 'city'

    newMember.Save();

    }

    else

    {

     

    //member exists

    }

    }

    You can watch Tim's version of Register.aspx.cs to see where they should be located.

    3) in ascx-file copy everything below the first line

    <

     

    asp:Label ID="lblName" runat="server" Text="Name:"></asp:Label><asp:TextBox ID="txtName"

     

    runat="server"></asp:TextBox><br />

    <

     

    asp:Label ID="lblEmail" runat="server" Text="Email:"></asp:Label><asp:TextBox ID="txtEmail"

     

    runat="server"></asp:TextBox><br />

     

    <asp:Label ID="lblAddress" runat="server" Text="Address:"></asp:Label><asp:TextBox ID="txtAddress"

     

    runat="server"></asp:TextBox><br />

     

     

    <asp:Label ID="lblCity" runat="server" Text="City:"></asp:Label><asp:TextBox ID="txtCity"

     

    runat="server"></asp:TextBox><br />

     

     

    <asp:Label ID="lblUsername" runat="server" Text="Username:"></asp:Label></asp:TextBox><asp:TextBox ID="txtUsername"

     

    runat="server"></asp:TextBox><br />

     

    <asp:Label ID="lblPassword" runat="server" Text="Password:"></asp:Label><asp:TextBox ID="txtPassword"

     

    runat="server" TextMode="Password"><br />

     

    <

     

    asp:Button ID="btnRegister" runat="server" Text="Register"

     

    onclick="btnRegister_Click" />

    Try that, and see what happens.

    /Fredrik

  • Evan 344 posts 99 karma points
    Aug 05, 2009 @ 17:35
    Evan
    0

    Thanks that seemed to have worked perfectly, thanks.

  • Fredrik Sewén 39 posts 106 karma points
    Aug 05, 2009 @ 17:36
    Fredrik Sewén
    0

    The styling looks a bit messed up in my last post, but hopefully you can find it by looking at the sample project from Tim or in his blog post.

    /Fredrik

  • Evan 344 posts 99 karma points
    Aug 05, 2009 @ 17:45
    Evan
    0

    I have everything somewhat working now, I changed the code behind file to go to id 1093 (the id of my membertype), but everytime I hit register I keep getting an error that says the following:   I have reset my cache and everything, any ideas?

    Server Error in '/' Application.

    No Contenttype with id: 1040

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException: No Contenttype with id: 1040

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [ArgumentException: No Contenttype with id: 1040]
    umbraco.cms.businesslogic.ContentType.setupContentType() +257
    UmbracoCreateMember.Register.btnRegister_Click(Object sender, EventArgs e) +199
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
  • Evan 344 posts 99 karma points
    Aug 05, 2009 @ 17:55
    Evan
    0

    Just did a search in the entire project an 1040 is not found anywhere, why would it be doing this?

  • Fredrik Sewén 39 posts 106 karma points
    Aug 05, 2009 @ 18:11
    Fredrik Sewén
    0

    Now it looks like it's taking the Click-event from the UmbracoCreateMember.dll that you added earlier.

    It's important that your declaration in ascx-file inherits from your cs-file

    ascx-file

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="usercontrols_WebUserControl" %>

    cs-file

    public

     

    partial class usercontrols_WebUserControl : System.Web.UI.UserControl

    It gets a bit more complicated if you have a namespace directive aswell. That depends on if you started the project as a website or webapplication in VS. Then you'll have to make sure your namespace is not the same as the one declared in the UmbracoCreateMember.dll.

  • Evan 344 posts 99 karma points
    Aug 05, 2009 @ 18:35
    Evan
    0

    ok Explain this again?  Where is it pulling 1040 from so I can change it to have it go to the correct membertype...

  • Evan 344 posts 99 karma points
    Aug 05, 2009 @ 19:26
    Evan
    0

    Any ideas, I just did another fresh copy and changed the id of the member type to 1093 and it always reverts back to 1040 somehow (not in the code, only on the website)  Please someone help me out!

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 05, 2009 @ 20:21
    Sebastiaan Janssen
    1

    I just created a new WebUserControl and referenced umbraco.dll, cms.dll and businesslogic.dll

    The code is as follows:

    member.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="member.ascx.cs" Inherits="CreateMember.WebUserControl" %>
    
    E-mailadres: <asp:TextBox runat="server" id="memberEmail" ></asp:TextBox>
    <br />
    <asp:Button ID="SubmitButton" runat="server" Text="Create member" onclick="SubmitButton_Click" />

    member.ascx.cs (replace YourMemberTypeAlias)!

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using umbraco.cms.businesslogic.member;
    
    
    namespace CreateMember
    {
        public partial class WebUserControl : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void SubmitButton_Click(object sender, EventArgs e)
            {
                if (Member.GetMemberFromEmail(memberEmail.Text) == null)
                {
                    MemberType mt = MemberType.GetByAlias("YourMemberTypeAlias");
    
                    Member newMember = Member.MakeNew(memberEmail.Text, mt, new umbraco.BusinessLogic.User(0));
    
                    newMember.Email = memberEmail.Text;
                    newMember.LoginName = memberEmail.Text;
                    newMember.Password = "test";
    
                    newMember.Save();
                }
            }
        }
    }

     

    Create a macro with this user control in it and place it in your template.

    Be sure to put the <form runat="server"> tag around the macro in your template.

    It works fine for me, you can build further upon this..

    Hope this helps you!

  • Fredrik Sewén 39 posts 106 karma points
    Aug 06, 2009 @ 08:56
    Fredrik Sewén
    0

    It seems as it's pulling the values from the createMember.dll that you added to the bin-files earlier. That file consists of a precompiled version of Tim's sample code. That's why you will not find 1040 in your solution.

    If you havn't solved it yet, can't you post your UserControl-files (both ascx- and cs-file) and we'll try to solve it from there. Also, remove the CreateMember.dll if it's in your bin-directory. Otherwise it might pull values from there.

Please Sign in or register to post replies

Write your reply to:

Draft