Declare Custom DLL Control in Code-Behind to set properties

  • Thread starter Technical Support
  • Start date
T

Technical Support

Good afternoon,
I created a custom control, compiled it into a DLL, and added it to the BIN
directory. I placed an instance of the control in a webForm and am trying to
programatically change its properties via the Page_Load subroutine in a
code-behind file. Can someone please tell me the proper procedure for
declaring the new custom control in the code-behind file? I have supplied
all of the code associated with this very basic example and am using VS.NET.
The solution's name is "Learn"

Thank you in advance.

Eric

Compiled Custom Control (showcolor.dll)
-------------------------------------------
Imports System
Imports System.Web
Imports System.Web.UI

Namespace myControls
Public Class ShowColor : Inherits Control
Public Text As String
Public Color As String
Protected Overrides Sub Render(ByVal objTextWriter As
HtmlTextWriter)
objTextWriter.AddAttribute("Color", Color)
objTextWriter.RenderBeginTag("Font")
objTextWriter.Write(Text)
objTextWriter.RenderEndTag()
End Sub
End Class
End Namespace
++++++++++++++++++++++++++

WebForm (DisplayShowColor.aspx)
---------------------------------------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="DisplayShowColor.aspx.vb" Inherits="learn.DisplayShowColor"%>
<%@ Register TagPrefix="myControls" Namespace="myControls"
Assembly="ShowColor" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>DisplayShowColor</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<TABLE height="39" cellSpacing="0" cellPadding="0" width="243"
border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD>
<myControls:ShowColor id="ctrlShowColor" Runat="server" />
</TD>
</TR>
</TABLE>
</body>
</HTML>
++++++++++++++++++++++++++++++++++++++

WebForm - Code-Behind (DisplayShowColor.aspx.vb)
---------------------------------------------------------
Public Class DisplayShowColor
Inherits System.Web.UI.Page
Protected ctrlShowColor As myControls.ShowColor
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ctrlShowColor.Text = "Hello Ethan"
ctrlShowColor.Color = "Orange"
End Sub
End Class
 
S

Steve C. Orr [MVP, MCSD]

Add the control to your toolbox, then drag the control from the toolbox onto
your form.
All the declarations should then happen automatically for you.
 
E

Eric

I only wish it were that easy :)

I did as you said and now am getting the following error:
The base class includes the field 'ShowColor1', but its type
(learn.myControls.ShowColor) is not compatible with the type of control
(myControls.ShowColor).

Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top