Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom control becomes generic "UserControl" and not its actual type in Designer class

I have a custom control in ASP.NET (VB.NET in code behind), defined with an ASCX:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="MyControl.ascx.vb" Inherits="Mynamespace.Controls.MyControl" %>

<!-- some html and other custom controls-->

And in code behind:

Namespace Controls

    Public Class MyControl
        Inherits System.Web.UI.UserControl

This is set in a library. A different project uses that control in a page:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="mypage.aspx.vb" 
    Inherits="myproject.mypage" culture="auto" meta:resourcekey="Page" uiculture="auto" 
    Transaction="RequiresNew" MasterPageFile="Mynamespace.Master" 
    Theme="ThemeBase2" StylesheetTheme="ThemeBase2" %>

<%@ Register tagprefix="Controls" tagname="MyControl" src="../Controls/MyControl.ascx" %>

<%-- some asp.net --%>

<Controls:MyControl ID="mycontrol1" runat="server" 
                    MyCustomProperty="value" />

However, when I build, I get an error saying

'MyCustomProperty' is not a member of 'System.Web.UI.UserControl'.

And in the designer.vb page I see:

Protected WithEvents mycontrol1 As Global.System.Web.UI.UserControl

How do I ensure it becomes:

Protected WithEvents mycontrol1 As Global.Mynamespace.Controls.MyControl

?

like image 682
MPelletier Avatar asked Dec 14 '15 22:12

MPelletier


People also ask

What is difference between user control and custom control in asp net?

The main difference between them- User Control is a page file with extension . ascx which can only be used within a single application or project But custom controls are assemblies(dll files) that can be used in multiple applications.

What is custom control in user interface design?

What Does Custom Control Mean? Custom control is a control that is not included in the . NET framework library and is instead created by a third-party software vendor or a user. Custom control is a concept used while building both Windows Forms client and ASP.NET Web applications.

Why would you use custom controls?

Controls are useful when you're developing complex applications because you can avoid code duplication. Because custom controls are objects, you can use the typical features offered by OOP. You can start from scratch with your own control, or use an existing control and enrich it.

What is control custom?

A software routine that adds some enhancement or feature to an application. Custom controls are written to provide as little as a few graphical interface improvements to as much as providing full imaging, spreadsheet and text editing extensions to the application.


2 Answers

Your ascx file is not accessible because it is in a library

You need to save the ascx file as an embedded resource of your library and load it as extern resource in your web application.

You can consult this link for more informations.

If you want share yours controls, i advise to create UserControl instead of CustomControl. Unfortunately, there is more work because the designer is not usable

like image 36
Troopers Avatar answered Oct 19 '22 23:10

Troopers


Make sure that MyControl is defined inside Global.Mynamespace.Controls.MyControl. It inherits this namespace, but it seems that this is supposed to be the namespace in which it is defined. Also, make sure that MyCustomProperty is defined, of course.

like image 54
ic3man7019 Avatar answered Oct 19 '22 23:10

ic3man7019