Custom Control in Toolbox

  • Thread starter Antonio Matos via .NET 247
  • Start date
A

Antonio Matos via .NET 247

(Type your message here)

--------------------------------
From: Antonio Matos

I have some problems with my custom web control to put it intothe toolbox. Where I work, there is some patterns to follow. SoI must use a file called Style1024.css, that contains a lot ofdefinitions. The problems is that I made my custom control (asimply button) which code is as follow:

====BotaoCPqD.ascx====

Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Web.UI.Design

<DefaultEvent("BotaoPressionado"), _
DefaultProperty("TextoBotao"), _
Description("Bot?o Web Padr?o CPqD")> _
Public MustInherit Class BotaoCPqD

Inherits System.Web.UI.UserControl

Protected WithEvents btnWebButton AsSystem.Web.UI.HtmlControls.HtmlTable
Protected WithEvents IMGButtonLeft AsSystem.Web.UI.HtmlControls.HtmlImage
Protected WithEvents TDButton AsSystem.Web.UI.HtmlControls.HtmlTableCell
Protected WithEvents AButtonText AsSystem.Web.UI.HtmlControls.HtmlAnchor
Protected WithEvents IMGButtonRight AsSystem.Web.UI.HtmlControls.HtmlImage

Public Event BotaoPressionado()

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private SubInitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web FormDesigner
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub TrataClique(ByVal sender As System.Object, ByVale As System.EventArgs) Handles AButtonText.ServerClick
RaiseEvent BotaoPressionado()
End Sub

<Browsable(True), _
Category("Misc"), _
Description("Texto do bot?o")> _
Public WriteOnly Property TextoBotao() As String
Set(ByVal Value As String)
AButtonText.InnerText = Value
End Set
End Property

Private Sub ResizeButton(ByVal sender As Object, ByVal e AsEventArgs) Handles btnWebButton.PreRender
TDButton.Style.Remove("WIDTH")
TDButton.Style.Add("WIDTH",AButtonText.InnerText.Length.ToString)

btnWebButton.Style.Remove("WIDTH")
btnWebButton.Style.Add("WIDTH",(AButtonText.InnerText.Length + IMGButtonLeft.Width +IMGButtonRight.Width).ToString)
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

End Class

==== HTML control definition (using fixed styles in Style1024.css===
<%@ Control Language="vb" AutoEventWireup="false"Codebehind="BotaoCPqD.ascx.vb" Inherits="BotaoCPqD.BotaoCPqD"TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<LINK href="http://localhost/css/Style1024.css" type="text/css"rel="stylesheet">
<script language="javascript"src="http://localhost/js/functionLib.js"type="text/javascript"></script>
<TABLE id="btnWebButton" style="WIDTH: 152px; HEIGHT: 2px"cellSpacing="0" cellPadding="0" width="152" border="0"runat="server">
<TR>
<TD style="HEIGHT: 11px"><IMG id="IMGButtonLeft" alt=""src="http://localhost/Images/Image_button_left.gif"runat="server"></TD>
<TD class="buttonDefault" id="TDButton" style="FONT-WEIGHT:bold; FONT-SIZE: 10pt; COLOR: white; FONT-FAMILY: Arial; HEIGHT:11px; TEXT-ALIGN: center" width="200" bgColor="#4d7497"runat="server"><A class="buttonDefault" id="AButtonText"runat="server">Botao</A></TD>
<TD style="HEIGHT: 11px"><IMG id="IMGButtonRight" height="16"alt="" src="http://localhost/Images/Image_button_right.gif"width="16" runat="server"></TD>
</TR>
</TABLE>

When I drag and drop it from the project explorer to a aspx page,it works just fine. But I want to put it in the toolbox. I readsomething about it, and a example tells to put some definitionsin the class, and after that, in the class definition, the twolines must exists:

Inherits Panel
Implements INamingContainer

But if I do not put these two lines, I can't put the control intothe toolbox. But if I put it, I can put the control in thetoolbox, but I have to take of the "InheritsSystem.Web.UI.UserControl" line from my control'simplementation. After I took this line off, the control stopsworking, and acts like a simple HTML table with no events (Isupose that the codebehind does not work anymore).

There are anyone who can help me???

Thanx

Antonio
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top