473,739 Members | 10,033 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_Selec tedIndexChanged (ByVal source As Object,
ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) 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 CreateChildCont rols method of the WCC using the
line:

AddHandler dg.ItemCommand, AddressOf Me.DataGrid1_Se lectedIndexChan ged

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 18 '05 #1
4 2125
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.publi c.dotnet.langua ges.vb,
microsoft.publi c.dotnet.langua ges.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*******@lyco s.com> wrote in message news:ee******** *************** ***@posting.goo gle.com...
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_Selec tedIndexChanged (ByVal source As Object,
ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) 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 CreateChildCont rols method of the WCC using the
line:

AddHandler dg.ItemCommand, AddressOf Me.DataGrid1_Se lectedIndexChan ged

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 18 '05 #2
"Raterus" <ra*****@spam.o rg> wrote in message news:<u#******* *******@tk2msft ngp13.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.publi c.dotnet.langua ges.vb,
microsoft.publi c.dotnet.langua ges.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.Componen tModel
Imports System.Web.UI
Imports System.web.UI.W ebControls

<DefaultPropert y("Text"), ToolboxData("<{ 0}:WebCustomCon trol1
runat=server></{0}:WebCustomCo ntrol1>")> Public Class
WebCustomContro l1
Inherits System.Web.UI.W ebControls.WebC ontrol

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

Dim DataTable As New DataTable

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

Dim selectColumn As New ButtonColumn
selectColumn.Bu ttonType = ButtonColumnTyp e.LinkButton
selectColumn.Co mmandName = "select"
selectColumn.Te xt = "select"

dg.Columns.Add( selectColumn)

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

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

dg.DataSource = DataTable
dg.DataBind()
dg.RenderContro l(output)
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArg s)

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_Se lectedIndexChan ged
Controls.Add(dg )

End Sub

'Public Sub bz()

Private Sub DataGrid1_Selec tedIndexChanged (ByVal source As Object,
ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
dg.ItemCommand

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

End Sub

End Class



"The Alchemist" <al*******@lyco s.com> wrote in message
news:ee******** *************** ***@posting.goo gle.com...
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 SelectedIndexCh anged(ByVal source As Object,
ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) 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 CreateChildCont rols method of the WCC using the
line:

AddHandler dg.ItemCommand, AddressOf Me.DataGrid1 SelectedIndexCh anged

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 18 '05 #3
"The Alchemist" <al*******@lyco s.com> wrote in message
news:ee******** *************** **@posting.goog le.com...
"Raterus" <ra*****@spam.o rg> wrote in message

news:<u#******* *******@tk2msft ngp13.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.Componen tModel
Imports System.Web.UI
Imports System.web.UI.W ebControls

<DefaultPropert y("Text"), ToolboxData("<{ 0}:WebCustomCon trol1
runat=server></{0}:WebCustomCo ntrol1>")> Public Class
WebCustomContro l1
Inherits System.Web.UI.W ebControls.WebC ontrol

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

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_Se lectedIndexChan ged
Controls.Add(dg )

End Sub


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

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

"The Alchemist" <al*******@lyco s.com> wrote in message
news:ee******** *************** ***@posting.goo gle.com...
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_Selec tedIndexChanged (ByVal source As Object,
ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) 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 CreateChildCont rols method of the WCC using the
line:

AddHandler dg.ItemCommand, AddressOf Me.DataGrid1_Se lectedIndexChan ged

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 18 '05 #5

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

Similar topics

2
2757
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. The problem is the article is in VisualBasic. I already get the collection to be recognized as a Data Source by the IDE. It populated the DataGrid correctly from the fields on the items object of the collection, but I can't get the DataGrid to...
0
1334
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 in the DataGrid so that the user can enter the missing data. If there is data, I hide the HyperLink control. The problem is I pass the DataGrid control to a class and let the class populate it and return it to the ASPX page. I just don't know...
1
1754
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 problem when user clicks on update in datagrid. My problem is that when I try to get customvalidation to work when user changes the value in the control, as i want this to be checked as soon as user changes the control. The custom control offers an
7
3342
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, theres a requirement to show a drop down menu list (this is a control I downloaded online) in one of the columns. For the purposes of this question, Ive implemented the drop down menu as a drop down list instead. Ive got all this working at this...
1
1506
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 manipulation etc etc. The control works perfectly when placed outside a templated control but when placed in, for instance, a datagrid EditItemTemplate, I get the following error on the DataBind Method: the dreaded "Object not set to a referance"...
9
2336
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 into the place holder. This is done dynamically based on the choice they selected. This user control has a datagrid in it that supports paging. When I click on the next or prev buttons of the datagrid in a user control it should display the next page...
4
5177
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 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...
2
19484
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
8794
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9484
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9342
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9211
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8218
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6756
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6056
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4572
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.