raising events in usercontrol

I have a content page that will contain a couple of updatepanels with usercontrols in them. In one usercontrol (ucHieReport) I'm raising an event (ShowSelectedCellMessage(CellMessage As String)).

In my content page I have a sub to show a popup message to the user (Protected Sub ShowMasterPageMessageWindow(Message As String)).

What I don't know is how to wire the event in the control up to the content page.

The content markup is this:
<asp:UpdatePanel ID="upReports" runat="server" UpdateMode="Conditional">
            <uc:HieReport runat="server" ID="ucHieReport" OnErrorOccurred="HandleUserControlErrors" />

Open in new window

usercontrol codebehind:

 Public Event ShowSelectedCellMessage(CellMessage As String)

In the codebehind of the content page if I do this  ucHieReport.  the intellisense does not show the event declared in the user control. I would think it should.
Who is Participating?
Rajar AhmedConnect With a Mentor ConsultantCommented:
try this,
'UserControl - Starts
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="customEvent.ascx.vb" Inherits="Vb_customEvent" %>
<asp:GridView ID="gvData" runat="server" Width="50px" 
         AutoGenerateColumns="false"  DataKeyNames="ID">
     <asp:TemplateField HeaderText="Id" >
                 <asp:Label id="lblTId" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
     <asp:TemplateField  HeaderText="Name" ItemStyle-Width="1px">
     <ItemTemplate >
     <asp:Label id="lblText" runat="server" Text='<%# Bind("name") %>'></asp:Label>
     <asp:TemplateField  HeaderText="Name" ItemStyle-Width="1px">
     <ItemTemplate >
     <asp:button id="btnText" runat="server" Text="Delete"></asp:button>
     </asp:TemplateField> </Columns>
    Imports System.Data
Partial Class Vb_customEvent
    Inherits System.Web.UI.UserControl
    Public Event ShowSelectedCellMessage As EventHandler

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        AddHandler gvData.RowCommand, AddressOf ShowSelectedCellMessage1
        Dim ds As DataSet = getDataSet()
        If Not IsPostBack Then
            gvData.DataSource = ds
        End If
    End Sub
    Public Shared Function getDataSet() As DataSet
        Dim ds As New DataSet
        Dim dt As DataTable
        Dim dr As DataRow
        Dim idCoulumn As DataColumn
        Dim nameCoulumn As DataColumn
        Dim i As Integer

        dt = New DataTable()
        idCoulumn = New DataColumn("ID", Type.GetType("System.String"))
        nameCoulumn = New DataColumn("Name", Type.GetType("System.String"))


        dr = dt.NewRow()
        dr("ID") = "1"
        dr("Name") = "Bill"

        dr = dt.NewRow()
        dr("ID") = 2
        dr("Name") = "Gates"

        Return ds
    End Function
    Protected Sub ShowSelectedCellMessage1(sender As Object, e As EventArgs)
        Dim _gridView As GridView = CType(sender, GridView)
        _gridView.EditIndex = -1
        RaiseEvent ShowSelectedCellMessage(sender, e)
    End Sub

End Class
'UserControl Ends

'Invoking Page - Starts
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="eventCall.aspx.vb" Inherits="Vb_eventCall" %>
<%@ Register Src="~/Vb/customEvent.ascx" TagPrefix="uc1" TagName="customEvent" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
        <uc1:customEvent runat="server" ID="customEvent1" OnShowSelectedCellMessage="customRowCommand_Click"  />

Partial Class Vb_eventCall
    Inherits System.Web.UI.Page

    Protected Sub customRowCommand_Click(sender As Object, e As EventArgs)
    End Sub
End Class

'Invoking Page - Ends

Open in new window

rutledgjAuthor Commented:
Well, that might work for a button but I don't see how I can incorporate that into how I'm raising the event.

In the control I have a gridview. On that gridview's RowCommand event I'm trying to raise the ShowSelectedCellMessage event.

So in the page load of the control, how do you add the new event to that (gvHIE_RowCommand)?

 Protected Sub gvHIE_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvHIE.RowCommand

        Dim _gridView As GridView = CType(sender, GridView)
        _gridView.EditIndex = -1
        RaiseEvent ShowSelectedCellMessage(e.CommandArgument.ToString)
End Sub

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.