Hi,
I have a situation where I have a user Control (ResultHeader.ascx) that has
a button. I am placing that control into a page (samplePage.aspx). I have
setup a custom event, that should from everything I read, it should fire and
be trappable in the parent page. I have seen two ways to do this...one
using "with Events" and the another by using the add handler method.
Neither seems to be functioning in my case. What am I doing wrong?
Thanks!
Ron
' SamplePage.aspx -- the actual page object
Public Class SamplePage
Inherits System.Web.UI.Page
Implements IResultContainer
Protected WithEvents RR As Results
Protected WithEvents RH As ResultHeader
Private _Title As String
Public ReadOnly Property Title() As String Implements IResultContainer.Title
Get
Return Page.ToString
End Get
End Property
Public ReadOnly Property Results() As IResult Implements
IResultContainer.IResults
Get
Return RR
End Get
End Property
Public ReadOnly Property Header() As ResultHeader Implements
IResultContainer.ResultHeader
Get
Return RH
End Get
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
RR = CType(Page.LoadControl("Results.ascx"), Results)
RH = CType(Page.LoadControl("ResultHeader.ascx"), ResultHeader)
End Sub
Private Sub RH_Buttonclicked(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RH.ButtonClicked
RH.CallbackTest("test") <-- this line is never getting called
End Sub
End Class
' ResultHeader.ascx -- the user control that contains the button
Public Class ResultHeader
Inherits System.Web.UI.UserControl
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected _Info As DataTable
Protected _Title As String
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected _RowCount As String
Public Event ButtonClicked(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim Container As IResultContainer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If TypeOf (Page) Is IResultContainer Then
Container = CType(Page, IResultContainer)
_Title = Container.Title
_Info = Container.IResults.GetResults(_Title)
_RowCount = Container.IResults.GetRowCount(_Info)
BindGrid()
TextBox1.Text = _Title & " Returned " & _RowCount & " rows"
End If
AddHandler Button1.Click, AddressOf Button_Clicked
End Sub
Private Sub Button_Clicked(ByVal sender As System.Object, ByVal e As
System.EventArgs)
RaiseEvent ButtonClicked(sender, e)
End Sub
Public Sub CallbackTest(ByVal message As String) <--- this line is never
getting called
Label1.Text = message
End Sub
Private Sub BindGrid()
DataGrid1.DataSource = (_Info)
DataGrid1.DataBind()
End Sub 1 1740
Never mind I figured it out.
I never instantiated the RH and RR objects. I added the New keyword and
removed the "RR = CType(Page.LoadControl("Results.ascx"), Results)" lines
and everything works as expected.
Ron
"RSH" <wa*************@yahoo.comwrote in message
news:e9**************@TK2MSFTNGP06.phx.gbl...
Hi,
I have a situation where I have a user Control (ResultHeader.ascx) that
has a button. I am placing that control into a page (samplePage.aspx). I
have setup a custom event, that should from everything I read, it should
fire and be trappable in the parent page. I have seen two ways to do
this...one using "with Events" and the another by using the add handler
method. Neither seems to be functioning in my case. What am I doing
wrong?
Thanks!
Ron
' SamplePage.aspx -- the actual page object
Public Class SamplePage
Inherits System.Web.UI.Page
Implements IResultContainer
Protected WithEvents RR As Results
Protected WithEvents RH As ResultHeader
Private _Title As String
Public ReadOnly Property Title() As String Implements
IResultContainer.Title
Get
Return Page.ToString
End Get
End Property
Public ReadOnly Property Results() As IResult Implements
IResultContainer.IResults
Get
Return RR
End Get
End Property
Public ReadOnly Property Header() As ResultHeader Implements
IResultContainer.ResultHeader
Get
Return RH
End Get
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
RR = CType(Page.LoadControl("Results.ascx"), Results)
RH = CType(Page.LoadControl("ResultHeader.ascx"), ResultHeader)
End Sub
Private Sub RH_Buttonclicked(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RH.ButtonClicked
RH.CallbackTest("test") <-- this line is never getting called
End Sub
End Class
' ResultHeader.ascx -- the user control that contains the button
Public Class ResultHeader
Inherits System.Web.UI.UserControl
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected _Info As DataTable
Protected _Title As String
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected _RowCount As String
Public Event ButtonClicked(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim Container As IResultContainer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If TypeOf (Page) Is IResultContainer Then
Container = CType(Page, IResultContainer)
_Title = Container.Title
_Info = Container.IResults.GetResults(_Title)
_RowCount = Container.IResults.GetRowCount(_Info)
BindGrid()
TextBox1.Text = _Title & " Returned " & _RowCount & " rows"
End If
AddHandler Button1.Click, AddressOf Button_Clicked
End Sub
Private Sub Button_Clicked(ByVal sender As System.Object, ByVal e As
System.EventArgs)
RaiseEvent ButtonClicked(sender, e)
End Sub
Public Sub CallbackTest(ByVal message As String) <--- this line is
never getting called
Label1.Text = message
End Sub
Private Sub BindGrid()
DataGrid1.DataSource = (_Info)
DataGrid1.DataBind()
End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alphonse Giambrone |
last post by:
I have a web form with 2 user controls on it (UC1 and UC2).
Each control has a bound datagrid with textboxes in the footer to add a new
row. There are also requiredfieldvalidators in each footer....
|
by: DotNetGuru |
last post by:
Hi,
I have nested User Controls like below.
User_Control_1
User_Control_11
User_Control_12(contains method DisplayMessage)
User_Control_2(contains event onButtonClick )
User_Control_1 and...
|
by: luca |
last post by:
Hi all.
My problem is that I can't handle events raised from child components within
a composite server control when the control is created dynamically.
Everything works fine if the same control...
|
by: Kris van der Mast |
last post by:
Hi,
been a while since I posted a question myself instead of trying to help
others out.
I'm refactoring an existing web app that uses dynamic loading of user
controls and a lot of...
|
by: Robert Howells |
last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad
architecture. I'd appreciate some feedback on the the wisdom (or lack
thereof) in attempting the following:
I'm not new...
|
by: Steve Booth |
last post by:
I have a web form with a button and a placeholder, the button adds a user
control to the placeholder (and removes any existing controls). The user
control contains a single button. I have done all...
|
by: scsharma |
last post by:
Hi,
I am working on creating a webapplication and my design calls for creating
main webform which will have menu bar on left hand side and a IFrame which
will contain all the forms that are shown...
|
by: c676228 |
last post by:
Hi,
I guess I am confused. In aspx script, I mean (you won't use
Codebehind="enrollinfo.aspx.vb", but mix code with html and code together)
You can access user control's property directly. Since I...
|
by: ChrisCicc |
last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |