More in this section

Forums / Developing with Sitefinity / user control in Vb could not load type

user control in Vb could not load type

5 posts, 0 answered
  1. Richard van der Helm
    Richard van der Helm avatar
    32 posts
    Registered:
    29 Oct 2005
    05 Jul 2007
    Link to this post
    Is it possible to create a usercontrol in Vb.net? I created a usercontrol with a code behind file in Vb.net. Uploaded it to page in edit mode. When i add it to a contentplaceholder on the page the error says could not load type "login". The control is basically the login box from the default loginpage with the code behind from that page.


  2. Richard van der Helm
    Richard van der Helm avatar
    32 posts
    Registered:
    29 Oct 2005
    05 Jul 2007
    Link to this post
    I kind of figured it out myself. Since there was no src tag in control directive  it would not load the code file. I thought that if you uploaded  a control and code file it would work the same way as the C# samples of tiu site usercontrols.

    So is this correct if i design a vb.net user control,  do I always have to put in this src tag manually?

    Furthermore. In VS 2005 if yoou create a new control, by default you get 3 files.
    - .ascx
    -. ascx.vb
    -.ascx.vb.designer.

    I can only upload code file. So what is the best practice to handle this? I now copied the designer code to the asc.vb file.

    thnx in advance
  3. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    06 Jul 2007
    Link to this post
    Hello richard van der Helm,

    I am not exactly sure how you get the error, but you do not need a src tag in the control directive in order for your user control to work. You don't need a ascx.vb.designer file, either. To hook up an .ascx file to a codebehind file, you need two settings in the control directive: CodeFile and Inherits. The CodeFile is the actual name of the file where your vb code is. The Inherits is the name of the partial class representing your user control in that file. I've included a sample user control that wraps up the functionality of the Sitefinity login page, with the code translated to Visual Basic. Please refer to the attached zip file. You should create user controls like in this example.

    Note: The text messages in the actual Login.aspx are retrieved from local resources for localization purposes. I've changed them to static text in the user control.
    Also note the <%@ Register %> directive, which enables you to use the FieldLabel tag.
    This sample control uses the Sitefinity membership provider to authenticate users against the Sitefinity database. You can use another provider by changing the code in the Page_Load method.

    If you have further questions, please don't hesitate to ask.

    Best wishes,
    Slavo
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. Richard van der Helm
    Richard van der Helm avatar
    32 posts
    Registered:
    29 Oct 2005
    06 Jul 2007
    Link to this post

    Thanks for yor reply. I made the same kind of control you send. Somehow yours works, mine ends up in could not load type error.

    Code ASCX 

    <%@ Control Language="VB" AutoEventWireup="false" CodeBehind="UC_Login.ascx.vb" Inherits="UC_Login" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="cc1" %>

     

      <div id="loginBox">
            <asp:Login ID="Login1" runat="server" >
                <layouttemplate>    
                    <fieldset>
                        <p class="failure"><asp:Label runat="server" id="FailureText" enableviewstate="False" style="color:Red" meta:resourcekey="FailureTextResource1" /></p>
                        <ol>                       
                            <li><cc1:FieldLabel ID="lblUsername" runat="server" TargetID="UserName" meta:resourcekey="lblUsernameResource1">Username:</cc1:FieldLabel></li>
                            <li><asp:textbox runat="server" id="UserName" accesskey="u" CssClass="login" meta:resourcekey="UserNameResource1" /><asp:requiredfieldvalidator runat="server" id="UserNameRequired" controltovalidate="UserName" validationgroup="LoginBox" ErrorMessage="*" tooltip="Username is required." CssClass="validator" meta:resourcekey="UserNameRequiredResource1" /></li>
                            <li><cc1:FieldLabel ID="lblPass" runat="server" TargetID="Password" meta:resourcekey="lblPassResource1">Password:</cc1:FieldLabel></li>
                            <li><asp:textbox runat="server"  id="Password" textmode="Password" accesskey="p" CssClass="login" meta:resourcekey="PasswordResource1" /><asp:requiredfieldvalidator runat="server" id="PasswordRequired" controltovalidate="Password" validationgroup="LoginBox" ErrorMessage="*" tooltip="Password is required." CssClass="validator" meta:resourcekey="PasswordRequiredResource1" /></li>
                           
                           
                 <li class="check"><cc1:FieldLabel ID="lblRemember" runat="server" TargetID="RememberMe" meta:resourcekey="lblRememberResource1"><asp:checkbox runat="server" id="RememberMe" meta:resourcekey="RememberMeResource1"/>Remember me on this computer</cc1:FieldLabel></li>
                            <li class="submit"><asp:Button ID="LoginButton" runat="server" CommandName="Login" CssClass="CmsBut" ValidationGroup="LoginBox" Text="LOGIN" meta:resourcekey="LoginButtonResource1"></asp:Button></li>
                        </ol>
                    </fieldset>
                </layouttemplate>
            </asp:Login>
          
        </div>
      


    CODE Code behind

    Imports Telerik.Security

     

    Partial Public Class UC_Login
        Inherits System.Web.UI.UserControl

     

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

            If Not IsPostBack Then

                     Me.Login1.MembershipProvider = UserManager.[Default].MembershipProvider.Name
            End If
            AddHandler Me.Login1.LoggedIn, AddressOf Login1_LoggedIn
            AddHandler Me.Login1.Authenticate, AddressOf Login1_Authenticate
        End Sub

        Sub Login1_Authenticate(ByVal sender As Object, ByVal e As AuthenticateEventArgs)
            e.Authenticated = UserManager.[Default].ValidateUser(Me.Login1.UserName, Me.Login1.Password)
        End Sub

        Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As EventArgs)
            Me.Page.Response.Redirect(Me.GetRedirectUrl(), True)
        End Sub

        Private Function GetRedirectUrl() As String
            Dim context As HttpContext = HttpContext.Current
            Dim returnUrl As String = context.Request.QueryString("ReturnUrl")
            If returnUrl = Nothing Then
                Return Me.Login1.DestinationPageUrl
            End If
            Return HttpUtility.UrlDecode(returnUrl)
        End Function


        Protected Overloads Overrides Sub OnPreRender(ByVal e As EventArgs)
            MyBase.OnPreRender(e)
            Dim script As String = "var txtBox = '" + Login1.FindControl("UserName").ClientID + "';"
            Me.Page.ClientScript.RegisterStartupScript(Me.[GetType](), "focus", script, True)
        End Sub


       End Class

  5. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    09 Jul 2007
    Link to this post
    Hi richard van der Helm,

    It is really strange that the same code works with my machine and does not work with yours. I searched for what might be the cause of the problem and it seems there are some issues when an ASP.NET application is not built. Try to open your project in Visual Studio and build it, together with the user control. For further information regarding this error, read the following materials:
    http://support.microsoft.com/kb/306155
    http://www.ironspeed.com/Designer/4.3.0/WebHelp/Part_VI/Parser_Error_Could_not_load_type.htm
    http://forums.aspfree.com/net-development-11/parser-error-message-could-not-load-type-17894.html

    Let me know if you solved your problem.

    All the best,
    Slavo
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
5 posts, 0 answered