Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2539
  • Last Modified:

asp.net event not firing through raiseevent

here's the scenario
page
    <asp:repeater ......
        <asp:UserControl>
        </asp:usercontrol>
    </asp:repeater>

Usercontrol
    <asp:linkbutton ... ></asp:linkbutton>

in the behind code for the user control, i have
public event evQueue
public sub linkbutton_click (....) handles linkbutton.click
    raiseevent evQueue
end sub

the problem on the first page, is im not able to catch this
i tried doing this
Private Sub QueueAct() handles usercontrol.evQueue

End Sub

but it doesnt fire it.. my guess is because the user control is in a repeater, so something must have to be done in the databound, any ideas?
0
mocaiv
Asked:
mocaiv
  • 2
1 Solution
 
Sammy AgeilCommented:
You need an EventHandler and to Raise it you do RaiseEvent(Me,e) where e is an EventArgs param

 Public Event Click As EventHandler
 Protected Overridable Sub OnClick(ByVal e As EventArgs)
     RaiseEvent Click(Me, e)
 End Sub
0
 
mocaivAuthor Commented:
didnt work

the code below doesnt work.. the testabc sub does not fire on raiseevent


Main Page
  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            Dim dt As New DataTable
            Dim dc As New DataColumn("abc")
            Dim dr As DataRow
            dt.Columns.Add(dc)
            dr = dt.NewRow
            dr(0) = "test"
            dt.Rows.Add(dr)

            Repeater1.DataSource = dt
            Repeater1.DataBind()
        End If
    End Sub
    Public Sub testabc(ByVal sender As Object, ByVal e As EventArgs)

    End Sub
    Private Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
        AddHandler CType(e.Item.Controls(1), WebUserControl2).evA, AddressOf testabc
    End Sub



User Control:

   Public Event evA As EventHandler

    Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        RaiseEvent evA(Nothing, Nothing)
    End Sub



main web (html)

<%@ Register TagPrefix="uc1" TagName="WebUserControl2" Src="WebUserControl2.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="Test1.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 MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:Repeater id="Repeater1" runat="server">
                        <ItemTemplate>
                              <uc1:WebUserControl2 id="WebUserControl21" runat="server"></uc1:WebUserControl2>
                        </ItemTemplate>
                  </asp:Repeater>
            </form>
      </body>
</HTML>




user control html  
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="WebUserControl2.ascx.vb" Inherits="Test1.WebUserControl2" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:LinkButton id="LinkButton1" runat="server">LinkButton</asp:LinkButton>

0
 
Sammy AgeilCommented:
try it with AutoEventWireup="true"
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now