I'm developing a SharePoint application using code-behind pages. I've got a WebGrid displaying data from a SharePoint list. I want to write an event-handler for the OnActiveRowChange event (cannot use auto wire-up in SharePoint code-behind). I've added event handlers for some buttons, but I get a compile time error when I try to add the handler for the OnActiveRowChange event:
"Cannot assign to 'OnActiveRowChange' because it is a 'method group'"
I'm running NetAdvantage 2008 V3, CLR 2.0
Any ideas on how to resolve this?
The assignment statement and method signature look correct to me.
I've touched base with a colleague who's more familiar with using WebGrid in a SharePoint scenario. She generally connects events to the grid at design-time on a user control; have you tested this? She also expects that adding the event handlers in the page's Init event would work.
You mentioned you tried doing this in OnInit, and that this also didn't work. I suggest a slightly different approach, which might affect timing slightly.
Ensure that your Page directive includes an AutoEventWireup attribute, and that this attribute is set to true. Next, add a method with the following signature:
protected void Page_Init(object sender, EventArgs e)
So long as you provide this signature (or at least this name and these parameters), the method should be called when the page's Init event is raised. Inside this method, establish the event handler for your grid's ActiveRowChange event.
If this doesn't get your event to work, then this will likely take some in-depth research to find out what's happening. If it comes to this point, I suggest you submit a support request so that a Developer Support Engineer can assist you further. It might be helpful if you provide a sample SharePoint project consisting of a WebGrid where you're unable to hook up to the ActiveRowChange event, since this will help ensure that we're testing the same code you're using.
I already had the "using" statement in my code. I changed the event handler name as you suggested and the solution compiled. When I ran it, though, SharePoint gives an "unexpected error" message. I tried putting the assignment in several different places, including in the event handler for a button click. When it was in the Page_Load event, the error message appeared when I tried to navigate to the page. When I moved it into the button click event handler, the error message appeared when I clicked the button. I removed all code from the ActiveRowChangeEventHandler routine, and it still gives the error message.
Here's my assignment statement:
uwgClientGrid.ActiveRowChange += new ActiveRowChangeEventHandler(uwgClientGrid_ActiveRowChange);
and here's my event handler definition:
protected void uwgClientGrid_ActiveRowChange(object sender, RowEventArgs e)
I usually post a fully-qualified namespace - my apologies for not doing so this time. I also mistyped the name of the event handler - it's "ActiveRowChangeEventHandler".
This identifier is defined in the Infragistics.WebUI.UltraWebGrid namespace. You can either prepend that namespace to the ActiveRowChangeEventHandler, or add a "using" statement to your page. I generally prefer the using statement approach.
Here's the error I got when I made that change and tried to build the project:
The type or namespace name 'AfterRowChangeEventHandler' could not be found (are you missing a using directive or an assembly reference?)
Where is that identifier 'AfterRowChangeEventHandler' defined - I could not find it.
Test the following line of code instead:
uwgClientGrid.ActiveRowChange += new AfterRowChangeEventHandler(uwgClientGrid_ActiveRowChange);
The name of the event is probably the more important of the two changes. I'm surprised that hooking up a handler to "OnActiveRowChange" would work, SharePoint or not.