I have an asp custom server control I have developed in order learn all about them. The objective was to have a custom control that could be added to a nested master page.
The custom control would hold a list of strings configured at design time. so the control is a collection of another control. it is located in two class files in the App_Code folder. The code for them is below
I have Two problems which I have searched high and low for all over the internet... im hoping someone here will help me...
1... I get the following warning
"Generation of designer file failed: Unknown server tag 'mvr:ColumnConfigurator'." which I cannot get rid of.
2... In the code behind file I cannot refer to the control by its "Id"... i.e. i want to be able to check the collection of strings before a page loads and perform some checks (show/hide columns on another control etc)
Imports System.ComponentModel
Imports System.Security.Permissions
Namespace MVRWebControls
< _
AspNetHostingPermission(System.Security.Permissions.SecurityAction.Demand, level:=AspNetHostingPermissionLevel.Minimal), _
AspNetHostingPermission(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal), _
ParseChildren(True, "Fields"), _
PersistChildren(False), _
DefaultProperty("Fields") _
> _
Partial Public Class ColumnConfigurator
Inherits System.Web.UI.Control
Private _Fields As System.Collections.Generic.List(Of CustomField)
< _
Category("Behavior"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
PersistenceMode(PersistenceMode.InnerDefaultProperty) _
> _
Public Property Fields() As System.Collections.Generic.List(Of MVRWebControls.CustomField)
Get
Return _Fields
End Get
Set(ByVal value As System.Collections.Generic.List(Of MVRWebControls.CustomField))
_Fields = value
End Set
End Property
Public Sub New()
End Sub
Protected Sub RenderContents(ByVal output As HtmlTextWriter)
Dim strText As String = ""
For Each f In Fields
strText = strText & f.Field
Next
output.Write(strText)
End Sub
End Class
End Namespace
And here is the object which is making up the collection above:
Imports System.ComponentModel
Namespace MVRWebControls
< _
ToolboxData("<{0}:CustomField runat=""server""></{0}:CustomField> "), _
DefaultProperty("Field") _
> _
Public Class CustomField
Inherits System.Web.UI.Control
< _
Category("Behavior"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
PersistenceMode(PersistenceMode.InnerDefaultProperty) _
> _
Private _Field As String
Public Property Field() As String
Get
Return _Field
End Get
Set(ByVal value As String)
_Field = value
End Set
End Property
Protected Sub RenderContents(ByVal output As HtmlTextWriter)
output.Write(Field)
End Sub
End Class
End Namespace
Ive registered the controls in the correct location in the web config file as follows
<add tagPrefix="mvr" namespace="MVRWebControls" />
And here is the page that tries to use it
<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/MasterPages/MVR.Master" CodeBehind="List.aspx.vb" Inherits="MVR.ValidationManager.List"
title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<mvr:ColumnConfigurator ID="ColConfig1" runat="server">
<mvr:CustomField ID="CustomField1" Field="ProjectId" runat="server"/>
<mvr:CustomField ID="CustomField2" Field="Title" runat="server" />
</mvr:ColumnConfigurator>
</asp:Content>