Creating Custom Controls

7331

New Member
I have posted a message similiar to this, but am still not sure how to accomplish what I am trying to accomplish. I want to be able to create my own tag with other ASP tags inside it. For example. <BR><BR>I would use my tag as shown below:<BR><BR><mytag:TableTag id="table" title="header title" runat="server"><BR> <asp:dropdownlist id="blah" runat="server"><BR> <BR><BR> This is a test.<BR></mytag:TableTag><BR><BR>I want the HTML that is generated to show up as shown below:<BR><BR><table><BR> <tr><BR> <td>Header title</td><BR> </tr><BR> <tr><BR> <td><BR> <select.....><BR> <BR><BR> This is a test...<BR> </td><BR> </tr><BR></table><BR><BR>This is an overly simplified example, but that is basically what I am trying to do. I want to create a wrapper around other controls. Does anyone have any example code for something like this? Any help would be appreciated.<BR><BR>Thanks.<BR><BR>ChaitanyaThere are two techniques, depending on the ParseChildrenAttribute.<BR>First, make sure your control includes the attribute (shown in C#):<BR>[ParseChildren(true or false)]<BR>public class TableTag : Table {...}<BR>When you use FALSE, the control expects anything between the opening and closing tags to be more ASP.NET controls (which I believe includes static text).<BR>When you use TRUE, it expects that you are declaring properties of the control itself, like <BackColor>Red</BackColor>.<BR>When true, you can use the Template methodology to allow users to embed controls into a property of your control. This is how DataGrid, Repeater and DataList allow customization.<BR><BR>In MSDN, see these topics:<BR>.Net FrameworkBuilding ApplicationsCreating ASP.NET Web ApplicationsDeveloping ASP.NET Server controls<BR>For ParseChildren, select this subtopic:<BR>Control Parsing, ParseChildrenAttribute...<BR>For Templates, select this subtopic:<BR>Developing a Templated Control<BR><BR>--- PeterI have managed to find all of that information, but am unable to determine what functions I should be putting the code in. I need to know the function to use when I start the tag and the function to use when I end the tag, OR I need to know in the Render function what and where to put the information regarding the ASP tags that are inside my tag. <BR><BR>In other words, where does this : <BR><table><BR> <tr><BR> <td><BR><BR>Where do the tags in the middle go?<BR><BR><asp:textbox.... /><BR><BR>And where does the end go:<BR><BR> </td><BR> </tr><BR></table><BR><BR>That's what the problem is. I just haven't been able to determine where this code is supposed to go. <BR><BR>ChaitanyaYou can use the panel control or create a custom (.ascx) control that you create.<BR><BR>You have to create the custom control properly though.<BR><BR>Here's a simple example:<BR><BR><BR>Save these lines as header.ascx<BR>************************************************** ******<BR><%@ Control Language="vb" AutoEventWireup="false" Codebehind="header.ascx.vb"%><BR><BR><asp:Label ID="header" Runat="server" Text="My custom header control" Height="25px" Width="100%" BackColor="#cccccc" ForeColor="#339999" Font-Size="20" font-bold="true" Font-Name="arial" BorderStyle="Outset"></asp:Label><BR>************************************************** *******<BR><BR>Save this line at the top of your ASPX:<BR><BR><%@ Register Tagprefix="Myheader" TagName="header" src=http://aspmessageboard.com/archive/index.php/"header.ascx" %><BR><BR><BR>Use this in you aspx to display the header:<BR><MyHeader:HEADER id="Header1" runat="server"></MyHeader:HEADER><BR>
 
Back
Top