This is a migrated thread and some comments may be shown as answers.

[Solved] Event Handling - Handle events raised by user control in CommandItemTemplate

1 Answer 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brad Hehe
Top achievements
Rank 1
Brad Hehe asked on 28 Sep 2009, 08:12 PM
I have built a custom user control and named it DataPartGridCommandItemTemplate.ascx  -- in this control there are the normal Add/Refresh buttons which simply use ASP:LinkButton and the respective CommandName properties ("InitInsert" and "RebindGrid")...

Additionally, I have a checkbox control that will ultimately "toggle" me between inline editing and popup forms...  So what I need is from within a UserControl (what I call "DataPartUserControl") that contains a RadGrid (what I call "DataPartGrid") which has its CommandItemTemplate built as follows:

<CommandItemTemplate> 
    <myWebApp:DataPartGridCommandItemTemplate ID="CommandItemTemplateUserControl" runat="server" ShowEditModeCommandItem="true" /> 
</CommandItemTemplate> 
 

The CheckBox control has its event wired-up and I can see that event fire just fine.  What I want to do then is raise my own custom event from the command item template user-control...   BUT...   Every time I check the public Event for null to ensure there is a subscriber before firing the event (and the subsequent null reference exception of course) - there are none.  

The initial wire-up to my command item template user-control was being performed in the DataPartGrid_ItemCreated event handler with the simple code of taking the GridCommandItem, using FindControls to find my command-item template user-control and then simply added the event handler...

After checking the forum, it seems like some other solutions were identified where moving the code to the PreRender event solved their problems. I tried this approach and what I found was that the CheckBox event handler was fired before PreRender so once again there was no subscriber to my user-control's published event...

So I'm not sure exacty how/when to get my event wire-up in the right place to ensure the event-wire up happens before the actual post-back event is dispatched to the check box event handler...

Alternately... Is there a better way of achieving this through using the same mechanisms as the LinkButton's use and creating a custom "CommandName" that I could bubble up?  If so, how would I access the grid from this nested user control and invoke the FireCommand method?

Thanks!



1 Answer, 1 is accepted

Sort by
0
Brad Hehe
Top achievements
Rank 1
answered on 28 Sep 2009, 09:05 PM
I found that Parent.NamingContainer does offer an object that inherits from GridItem which means I have access to the FireCommandEvent method...  I'm currently running with this approach...

All the same, how would I use the Event model above - seems I should have been able to utilize either approach...
Tags
Grid
Asked by
Brad Hehe
Top achievements
Rank 1
Answers by
Brad Hehe
Top achievements
Rank 1
Share this question
or