Custom Control in Toolbox

Discussion in 'ASP .Net Web Controls' started by Antonio Matos via .NET 247, May 14, 2004.

  1. (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

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>in7mRu4l8kCel0qDqoBtDw==</Id>
     
    Antonio Matos via .NET 247, May 14, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Prasanna Padmanabhan

    add custom control to toolbox

    Prasanna Padmanabhan, Jul 3, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    3,646
    Prasanna Padmanabhan
    Jul 3, 2003
  2. Showjumper
    Replies:
    2
    Views:
    2,405
    Benjie Fallar
    Jul 18, 2003
  3. Showjumper
    Replies:
    2
    Views:
    2,370
    Showjumper
    Jul 22, 2003
  4. Erik Cruz

    Custom control and toolbox tabs

    Erik Cruz, Jan 17, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    469
    Mohammad A. Samara
    Jan 17, 2004
  5. Dave
    Replies:
    0
    Views:
    469
Loading...

Share This Page