Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 3rd, 2005, 06:22 AM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default PLEASE HELP - Composite Control

Hi All.

I'm trying to create a composite control. At the moment it is just a test so I have the composite control which contains a normal datagrid.

What I need to know is, from the custom control, how do I fire an OnItemCreated Event in the code behind file for the webform that the control is in.

Also, How do I pass in DatagridEventArgs to this Method.

I have attached the code I have so far.

Any help would be greatly appreciated.

Thanks.

=== COMPOSITE CONTROL ================================================

Imports System.ComponentModel
Imports System.Web.UI

Public Class BKDG
    Inherits System.Web.UI.WebControls.WebControl
    Implements INamingContainer

    Dim DG1 As New WebControls.DataGrid

    Public Property BKDataGrid() As WebControls.DataGrid
        Get
            Return DG1
        End Get
        Set(ByVal Value As WebControls.DataGrid)
            DG1 = Value
        End Set
    End Property

    Protected Overrides Sub CreateChildControls()
        Controls.Add(DG1)
    End Sub

    Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
        output.Write("<table cellpadding=0 cellspacing=0 border=0>")
        output.Write("<tr>")
        output.RenderBeginTag("td")
        BKDataGrid.RenderControl(output)
        output.RenderEndTag()
        output.Write("</tr>")
        output.Write("</table>")
    End Sub

End Class


=== CODEBEHIND FILE ==================================================

Public Class WebForm1
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

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

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object
    Dim DB As New Database
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents MasterGrid As New BKControl.BKDG

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

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        MasterGrid.BKDataGrid.DataSource = DB.getDataSet("SELECT * FROM person")
        MasterGrid.BKDataGrid.DataBind()
    End Sub

    Public Sub SetLabel(ByVal Sender As Object, ByVal E As EventArgs)
        Label1.Text = "THIS WORKS"
    End Sub

End Class


=== WEB FORM ================================================== =======

<%@Register TagPrefix="BK" NameSpace="BKControl" Assembly="BKControl" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="BKControlTest.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>WebForm1</title>
        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">
            <BK:BKDG id="MasterGrid" runat="server" OnItemCreated="SetLabel" />
            <asp:Label id="Label1" runat="server"></asp:Label>
        </form>
    </body>
</HTML>



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Templates in a Composite Control dparsons ASP.NET 2.0 Professional 0 April 24th, 2008 12:28 PM
Chp.5 composite control properties studen77 BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 1 October 6th, 2006 03:35 PM
Composite Control Part 2 origjones General .NET 2 September 18th, 2006 03:28 AM
Building composite Control with Image + DDL mehdi_tn ASP.NET 2.0 Professional 1 April 12th, 2006 10:48 PM
Composite Control bmains .NET Framework 2.0 0 July 25th, 2005 12:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.