[Last Call] Learn how to a build a cloud-first strategyRegister Now


raising events in usercontrol

Posted on 2012-09-20
Medium Priority
Last Modified: 2012-09-21
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.
Question by:rutledgj
  • 2

Author Comment

ID: 38418897
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

LVL 18

Accepted Solution

Rajar Ahmed earned 2000 total points
ID: 38418987
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


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month18 days, left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question