View Single Post
Old August 3rd, 2005, 06:22 AM
brettk_1 brettk_1 is offline
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.


=== 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
            Return DG1
        End Get
        Set(ByVal Value As WebControls.DataGrid)
            DG1 = Value
        End Set
    End Property

    Protected Overrides Sub CreateChildControls()
    End Sub

    Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
        output.Write("<table cellpadding=0 cellspacing=0 border=0>")
    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.
    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")
    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">
        <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="">
        <form id="Form1" method="post" runat="server">
            <BK:BKDG id="MasterGrid" runat="server" OnItemCreated="SetLabel" />
            <asp:Label id="Label1" runat="server"></asp:Label>