Last post Nov 09, 2010 03:55 PM by Leeg32
Jan 07, 2009 12:27 PM|FrankStanssens|LINK
I have a custom control which contains a gridview with fields and a button field.
That custom control is placed on a page at runtime for more than 50 times in a panel (tried an updatepanel but didn't work neither)
Why doesn't the rowcommand fire when a button in the gridview is pushed?
Thx in advance,
Code in ASCX (removed non important code):
DT = DataSvc.High5Statistiek(mK4, mPeriode)
mSwitched = DT.Select(
mPlusNorm = DT.Select(
gvHigh5.DataSource = DT
mK4 = value
mPeriode = value
mLanguage = value
If e.Row.RowIndex = -1
e.Row.Cells(12).Text = 0
mShowIfEmpty = value
code for main page:
retValue = DataSvc.GetCurrentProductionMonth()
retValue = (retValue \ 100) * 100 + 7
retValue = (retValue \ 100) * 100 + 1
retValue = DataSvc.GetCurrentProductionMonth
retValue -= 6
retValue -= 94
DTStructure = DataSvc.High5Nationaal(StartHuidigePeriode)
hgSwitch = LoadControl(
.K4 = DR.Item(0)
.Language = strLanguage
.Periode = StartVorigePeriode()
Jan 07, 2009 01:06 PM|Careed|LINK
Okay, I haven't look at the entire code; however, in your RowCommand event method, you are making a call to Console.WriteLine. If this even works, it will more than likely open a Command window on the server and the user will not see it.
So, do you really want to use a Console object in a web application?
Jan 07, 2009 04:55 PM|FrankStanssens|LINK
no, it's just something i use to put the bookmark on and watch the values of the parameters
Jan 07, 2009 05:12 PM|JByrd2007|LINK
In your control declaration, you have the AutoEventWireup property set to false which means you don't want events propagated from the control (the default is true).
Is there a reason you have this turned off?
Normally, I think the user control (which is a container) will raise ItemCommand events with info on the event rather than separate control events (of which there could be many), so you may want to add an ItemCommand event handler and see if this is being
raised when you click on a row in your GridView.
Hope this helps,
User control AutoEventWireup
Jan 07, 2009 09:59 PM|Careed|LINK
So, what is the RowCommand supposed to do? Have you verified that the RowCommand is actually not firing through tracing?
Jan 08, 2009 04:39 AM|FrankStanssens|LINK
Turned the autoeventwireup to true, no result
Do you have an example on the ItemCommand?
it's not firing
Jan 08, 2009 09:39 AM|Careed|LINK
Try creating a new, smaller application where you have a simple user control with a GridView that you load onto a web page. Remove all of the extraneous properties and features that are not germane so that you can try to pin down where the problem is occurring.
Jan 08, 2009 10:13 AM|JByrd2007|LINK
Sorry, I was barking up the wrong tree as they say...
Events from the User Control aren't progagated to the page (which is where I'm assuming you're trying to catch them?), the easiest way to fix this is to:
1) Add a public event to your user control (which is then visible to the page):
Public event EventHandler RowCommand
Protected Sub gvHigh5_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If Not RowCommand Is Nothing Then
Protected Sub LoadSwitchData()
uc1.RowCommand += New EventHandler(hgSwitch_RowCommand)
Private Sub hgSwitch _RowCommand(ByVal sender As Object, ByVal e As EventArgs)
Dim args As GridViewCommandEventArgs = e as GridViewCommandEventArgs
If Not args Is Nothing Then
' Do your processing here.
I'm not a VB person, so I translated this from C# using one of the many web translators.
Hope this helps solve your problem!
User control EventHandler Raising events
Nov 09, 2010 03:55 PM|Leeg32|LINK
I know this is an old thread. However, I wanted to add on to this by describing a situation where a .Net page wasn't firing the rowcommand.
I was debugging another person's code when I realized why it wouldn't work. There were two user controls on the page with the SAME gridview name. One of the gridviews would actually work but the other didn't. The other person had copied over code into
a different usercontrol but left the name of the gridview the same.
Yea, after renaming the gridview so that everything was now completely unique, it all worked.