Tech Off Post

Single Post Permalink

View Thread: ASP.Net User control with codebehind not working
  • User profile image
    qwert231

    I have several pages that use the same collection of controls, an Img, and a couple of labels. I figured I could write a Usercontrol that would wrap everything up. I also wanted to programmatically read properties of this control to tell me whether the image was horizontal (width>height) or vertical (square counts as vertical).

    So I lay my controls into the ASCX file, and then go into the codebehind create some public (readonly properties). No compile errors.
    In my ascx file at the top I put this:
    <%@ Control Inherits="uCtrlPreview" src="uCtrlPreview.vb" %>


    I go into my first page (page1.aspx), give it a register tag, go down, put in my usercontrol tag. So far so good.
    <%@ Register TagPrefix="UserControl" TagName="PrevImg" Src="previewImg.ascx"
    %>
    ...
    <body>
    ...
    USERCONTROL:PrevImg id="Preview1" runat="Server"></USERCONTROL:PrevImg>


    I go into my page's (page1.aspx) codebehind and put this line:
    Protected WithEvents Preview1 As uCtrlPreview

    I get this message:
    The base class includes the field 'Preview1', but its type
    (ICUser.uCtrlPreview) is not compatible with the type of control
    (ASP.previewImg_ascx).

    Any ideas?