473,395 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Declare Custom DLL Control in Code-Behind to set properties

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
Nov 18 '05 #1
2 1645
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.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Technical Support" <su*****@dolphinbaydesigns.com> wrote in message
news:F6********************@adelphia.com...
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

Nov 18 '05 #2
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?

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:ub**************@TK2MSFTNGP11.phx.gbl...
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.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Technical Support" <su*****@dolphinbaydesigns.com> wrote in message
news:F6********************@adelphia.com...
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


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Tinus | last post by:
Hello all, I've create a custom control (UserControl) and have a custom Item Collection. The control is a custom calendar which is draw using the Graphics Rectangle etc. functions. It is drawn...
21
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
6
by: Suzanne | last post by:
Hi all, I really hope someone out there can help me as I've been tearing my hair out on this one for a good while and I'm getting really frustrated now! My problem is this - my custom...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
4
by: Charles Zhang | last post by:
I created a custom server control whose rendering logic relies on session variables and cookies. It works just fine at run time. The problem is at the design time, because session variables and...
1
by: rn5a | last post by:
I have created a custom control button which when clicked displays a message in the JavaScript alert dialog. I could successfully compile the VB class file into a DLL & also could add it to the...
3
by: stevong | last post by:
Hi, I've a custom user control: 'user1.ascx <script language="VB" runat="server"> Public str1 as string Dim conn as System.Data.SqlClient ' But this line hits and error. What should I do?
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.