473,513 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Web Custom Control - Datagrid Event Handling Problem

I am having a problem with a dynamically-generated Datagrid. It is
important to point out that this problem does not exist with a
design-time created Datagrid, but only with a dynamically generated
Datagrid in a Web Custom Control (WCC) :

The datagrid has LinkButton Column which has a select LinkButton for
each row. When this button is clicked, the Datagrid raises its
'ItemCommand' event which captures the information for that row and
sends it to a event handler method. The problem is that this method is
never getting called. It seems logical to assume that there is
something wrong with the event-wiring of the datagrid. The signature
of the event-handler is:

Private Sub DataGrid1_SelectedIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dg.ItemCommand

(dg is the name of the datagrid). The 'Handles' keyword in VB.Net is
supposed to wire the event to the handler but that is not happening.
So I tried to manually add the handler to the event with the following
line of code in the CreateChildControls method of the WCC using the
line:

AddHandler dg.ItemCommand, AddressOf Me.DataGrid1_SelectedIndexChanged

That does not work either. The datagrid loads up just fine, and on
selecting a row it does a PostBack and hits the OnLoad event but never
hits the event-handler method.

Why is this event not being wired to the handler? Or might there be
some other problem?

Thanks in advance for any help.

BZ
Nov 20 '05 #1
4 5168
Please don't crosspost, this post has no business in these forums as it has nothing to do with VB or VB's controls.

microsoft.public.dotnet.languages.vb,
microsoft.public.dotnet.languages.vb.controls

I'll be nice though and answer your question, you haven't re-instantiated your datagrid in page_load of the postbacked page, and given it the same ID as the previous page had.

"The Alchemist" <al*******@lycos.com> wrote in message news:ee**************************@posting.google.c om...
I am having a problem with a dynamically-generated Datagrid. It is
important to point out that this problem does not exist with a
design-time created Datagrid, but only with a dynamically generated
Datagrid in a Web Custom Control (WCC) :

The datagrid has LinkButton Column which has a select LinkButton for
each row. When this button is clicked, the Datagrid raises its
'ItemCommand' event which captures the information for that row and
sends it to a event handler method. The problem is that this method is
never getting called. It seems logical to assume that there is
something wrong with the event-wiring of the datagrid. The signature
of the event-handler is:

Private Sub DataGrid1_SelectedIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dg.ItemCommand

(dg is the name of the datagrid). The 'Handles' keyword in VB.Net is
supposed to wire the event to the handler but that is not happening.
So I tried to manually add the handler to the event with the following
line of code in the CreateChildControls method of the WCC using the
line:

AddHandler dg.ItemCommand, AddressOf Me.DataGrid1_SelectedIndexChanged

That does not work either. The datagrid loads up just fine, and on
selecting a row it does a PostBack and hits the OnLoad event but never
hits the event-handler method.

Why is this event not being wired to the handler? Or might there be
some other problem?

Thanks in advance for any help.



BZ

Nov 20 '05 #2
"Raterus" <ra*****@spam.org> wrote in message news:<u#**************@tk2msftngp13.phx.gbl>...
Please don't crosspost, this post has no business in these forums as it
has nothing to do with VB or VB's controls.

microsoft.public.dotnet.languages.vb,
microsoft.public.dotnet.languages.vb.controls
This control is written in VB.Net, how can it not be relevant to these
groups?

I'll be nice though and answer your question, you haven't
re-instantiated your datagrid in page load of the postbacked page, and
given it the same ID as the previous page had.
Yes I did and it does not not work.

I am posting the code below, any help would be MUCH appreciated.
Imports System.ComponentModel
Imports System.Web.UI
Imports System.web.UI.WebControls

<DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")> Public Class
WebCustomControl1
Inherits System.Web.UI.WebControls.WebControl

Protected WithEvents dg As DataGrid
Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)

Dim DataTable As New DataTable

Dim col As New DataColumn
col.ColumnName = "Last Name"
DataTable.Columns.Add(col)
Dim col2 As New DataColumn
col2.ColumnName = "First Name"
DataTable.Columns.Add(col2)
Dim col3 As New DataColumn
col3.ColumnName = "Level"
DataTable.Columns.Add(col3)

Dim selectColumn As New ButtonColumn
selectColumn.ButtonType = ButtonColumnType.LinkButton
selectColumn.CommandName = "select"
selectColumn.Text = "select"

dg.Columns.Add(selectColumn)

Dim row As DataRow
row = DataTable.NewRow
row.Item(0) = "Smith"
row.Item(1) = "John"
row.Item(2) = "Level 1"
DataTable.Rows.Add(row)

row = DataTable.NewRow
row.Item(0) = "Jones"
row.Item(1) = "Mary"
row.Item(2) = "Level 2"
DataTable.Rows.Add(row)

dg.DataSource = DataTable
dg.DataBind()
dg.RenderControl(output)
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

dg = New DataGrid
dg.BackColor = System.Drawing.Color.Red
dg.ID = "testID"
'I tried the following line instead of using the handles
keyword and that didnt work either:
'AddHandler dg.ItemCommand, AddressOf
Me.DataGrid1_SelectedIndexChanged
Controls.Add(dg)

End Sub

'Public Sub bz()

Private Sub DataGrid1_SelectedIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dg.ItemCommand

Debug.WriteLine("The event handler has been called.")

End Sub

End Class



"The Alchemist" <al*******@lycos.com> wrote in message
news:ee**************************@posting.google.c om...
I am having a problem with a dynamically-generated Datagrid. It is
important to point out that this problem does not exist with a
design-time created Datagrid, but only with a dynamically generated
Datagrid in a Web Custom Control (WCC) :

The datagrid has LinkButton Column which has a select LinkButton for
each row. When this button is clicked, the Datagrid raises its
'ItemCommand' event which captures the information for that row and
sends it to a event handler method. The problem is that this method is
never getting called. It seems logical to assume that there is
something wrong with the event-wiring of the datagrid. The signature
of the event-handler is:

Private Sub DataGrid1 SelectedIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dg.ItemCommand

(dg is the name of the datagrid). The 'Handles' keyword in VB.Net is
supposed to wire the event to the handler but that is not happening.
So I tried to manually add the handler to the event with the following
line of code in the CreateChildControls method of the WCC using the
line:

AddHandler dg.ItemCommand, AddressOf Me.DataGrid1 SelectedIndexChanged

That does not work either. The datagrid loads up just fine, and on
selecting a row it does a PostBack and hits the OnLoad event but never
hits the event-handler method.

Why is this event not being wired to the handler? Or might there be
some other problem?

Thanks in advance for any help.

BZ

Nov 20 '05 #3
"The Alchemist" <al*******@lycos.com> wrote in message
news:ee*************************@posting.google.co m...
"Raterus" <ra*****@spam.org> wrote in message

news:<u#**************@tk2msftngp13.phx.gbl>...
I'll be nice though and answer your question, you haven't
re-instantiated your datagrid in page load of the postbacked page, and
given it the same ID as the previous page had.


Yes I did and it does not not work.

I am posting the code below, any help would be MUCH appreciated.
Imports System.ComponentModel
Imports System.Web.UI
Imports System.web.UI.WebControls

<DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")> Public Class
WebCustomControl1
Inherits System.Web.UI.WebControls.WebControl

Protected WithEvents dg As DataGrid
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

dg = New DataGrid
dg.BackColor = System.Drawing.Color.Red
dg.ID = "testID"
'I tried the following line instead of using the handles
keyword and that didnt work either:
'AddHandler dg.ItemCommand, AddressOf
Me.DataGrid1_SelectedIndexChanged
Controls.Add(dg)

End Sub


How about MyBase.OnLoad(e)
--
John Saunders
johnwsaundersiii at hotmail
Nov 20 '05 #4
Hi,

I am experiencing the same problem as you are.
Have you got any solution?

"The Alchemist" <al*******@lycos.com> wrote in message
news:ee**************************@posting.google.c om...
I am having a problem with a dynamically-generated Datagrid. It is
important to point out that this problem does not exist with a
design-time created Datagrid, but only with a dynamically generated
Datagrid in a Web Custom Control (WCC) :

The datagrid has LinkButton Column which has a select LinkButton for
each row. When this button is clicked, the Datagrid raises its
'ItemCommand' event which captures the information for that row and
sends it to a event handler method. The problem is that this method is
never getting called. It seems logical to assume that there is
something wrong with the event-wiring of the datagrid. The signature
of the event-handler is:

Private Sub DataGrid1_SelectedIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dg.ItemCommand

(dg is the name of the datagrid). The 'Handles' keyword in VB.Net is
supposed to wire the event to the handler but that is not happening.
So I tried to manually add the handler to the event with the following
line of code in the CreateChildControls method of the WCC using the
line:

AddHandler dg.ItemCommand, AddressOf Me.DataGrid1_SelectedIndexChanged

That does not work either. The datagrid loads up just fine, and on
selecting a row it does a PostBack and hits the OnLoad event but never
hits the event-handler method.

Why is this event not being wired to the handler? Or might there be
some other problem?

Thanks in advance for any help.

BZ

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2705
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
0
1325
by: Sam | last post by:
Hi, I have a class that receives a DataGrid control and populates it. However, I need to do an OnItemCreated event because if I'm missing data in a certain column, I display a HyperLink control...
4
2108
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
1
1739
by: philipl | last post by:
hi, i have a datagrid which display custom controls when user clicks edit, changing data. I am using customvalidator to validate this control. I can get validation of user input to work no...
3
2835
by: WebMatrix | last post by:
I am struggling with implementing somewhat complicated UI web-control. I explored Repeater, but I am not sure if it's the best way to go. I am leaning towards writing my own custom control and...
7
3327
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
1
1497
by: Sam Samnah | last post by:
Hi Everyone. It has been a long time since my last post. Nevertheless, I have built a custom server control that allows a user to edit text, bolding, italics strike though table insertion and...
9
2315
by: Sridhar | last post by:
Hi, I have created a web page which includes a place holder. I also have a dropdown list in that webpage. when I select one of the choices in that dropdown list, It will load a user control...
2
19405
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
2897
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7101
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...
0
7525
tracyyun
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...
1
5089
isladogs
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...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.