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

Help with Custom Edit Form Controls

3 Answers 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Liza
Top achievements
Rank 1
Liza asked on 18 Feb 2009, 11:06 PM
Hi! I'm using a custom edit form with a web user control. In this web user control 
In this control I have an asp:button and I want to control the events for this control in the ItemCommand event of the radGrid. But when I try to access the button on this custom control I get nothing (this only occurs on RadGrid.InitInsertCommandName or RadGrid.EditCommandName)

Please, can you help me? And the most important thing, can I do what I'm trying to do?

This is the code that I have:

Dim MyUserControl As New UserControl 
 
Select Case e.CommandName 
 
       Case RadGrid.InitInsertCommandName, RadGrid.EditCommandName 'here i want to add a postback controling into the RadAjaxManager of the RadGrid 
      
            MyUserControl = CType(e.Item.FindControl(GridEditFormInsertItem.EditFormUserControlID), UserControl) 
 
            If Not IsDBNull(CType(MyUserControl.FindControl("btnAddDoc"), Button)) Then 
              
               RadAjaxManager1.AjaxSettings.AddAjaxSetting(CType(MyUserControl.FindControl("btnAddDoc"), Button), _
                                                           CType(MyUserControl.FindControl("lstActiveDocs"), ListBox))                            
               RadAjaxManager1.AjaxSettings.AddAjaxSetting(CType(MyUserControl.FindControl("btnAddDoc"), Button), _
                                                           CType(MyUserControl.FindControl("lstRelateDocs"), ListBox)) 
            End If                    
                 
       Case "AddDocs" 'here I want to control the button click event 
 
            MyUserControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl) 
 
            'code for button click event 
            '       ... 
            '       ... 
            '       ... 
       
       Case RadGrid.CancelCommandName 'here i want to remove the postback controling into the RadAjaxManager of the RadGrid 
 
            For intX As Integer = 1 To RadAjaxManager1.AjaxSettings.Count - 1                       
                RadAjaxManager1.AjaxSettings.RemoveAt(intX) 
            Next intX 
End Select 

Thanks,
Liza

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Feb 2009, 06:20 AM
Hello Liza,

It is too early to access the UserControl in the EditCommand or InsertCommand events. You can access the UserControl and thereby the button contained in the UserControl, in the ItemCreated/ItemDataBound event of the grid as shown below:
cs:
       Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) 
         If TypeOf e.Item Is GridEditableItem AndAlso (e.Item.IsInEditMode OrElse e.Item.OwnerTableView.IsItemInserted) Then 
             Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem) 
             Dim MyUserControl As UserControl = DirectCast(editItem.FindControl(GridEditFormItem.EditFormUserControlID), UserControl) 
             
             If Not (DirectCast(MyUserControl.FindControl("btnAddDoc"), Button) = System.DBNull.Value) Then 
                 RadAjaxManager1.AjaxSettings.AddAjaxSetting(DirectCast(MyUserControl.FindControl("btnAddDoc"), Button), DirectCast(MyUserControl.FindControl("lstActiveDocs"), ListBox)) 
                 RadAjaxManager1.AjaxSettings.AddAjaxSetting(DirectCast(MyUserControl.FindControl("btnAddDoc"), Button), DirectCast(MyUserControl.FindControl("lstRelateDocs"), ListBox)) 
             End If 
         End If 
     End Sub 

Thanks
Princy.
0
Liza
Top achievements
Rank 1
answered on 19 Feb 2009, 09:00 PM
Hi! Thanks for answering so quickly.
I was trying to do what you put in that code, but I still having a NullReferenceExceptionError, and when I debug this code and check for MyUserControl value, this is nothing.
VB:
Protected Sub rdgDocsView_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rdgDocsView.ItemCreated 
 
   If TypeOf e.Item Is GridEditableItem AndAlso (e.Item.IsInEditMode OrElse e.Item.OwnerTableView.IsItemInserted) Then 
      Dim MyUserControl As UserControl = DirectCast(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl) 
 
      If Not IsDBNull(CType(MyUserControl.FindControl("btnAddDoc"), Button)) Then
             RadAjaxManager1.AjaxSettings.AddAjaxSetting(CType(MyUserControl.FindControl("btnAddDoc"), Button), _ 
                                                 CType(MyUserControl.FindControl("lstActiveDocs"), ListBox))
             RadAjaxManager1.AjaxSettings.AddAjaxSetting(CType(MyUserControl.FindControl("btnAddDoc"), Button), _ 
                                                         CType(MyUserControl.FindControl("lstRelateDocs"), ListBox)) 
      End If 
   End If 
End Sub 

Sorry, but what can I do?

Thanks,
Liza
0
Liza
Top achievements
Rank 1
answered on 19 Feb 2009, 09:01 PM
Hi! Thanks for answering so quickly.
I was trying to do what you put in that code, but I still having a NullReferenceExceptionError, and when I debug this code and check for MyUserControl value, this is nothing.
VB:
Protected Sub rdgDocsView_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rdgDocsView.ItemCreated 
 
   If TypeOf e.Item Is GridEditableItem AndAlso (e.Item.IsInEditMode OrElse e.Item.OwnerTableView.IsItemInserted) Then 
      Dim MyUserControl As UserControl = DirectCast(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl) 
 
      If Not IsDBNull(CType(MyUserControl.FindControl("btnAddDoc"), Button)) Then
             RadAjaxManager1.AjaxSettings.AddAjaxSetting(CType(MyUserControl.FindControl("btnAddDoc"), Button), _ 
                                                 CType(MyUserControl.FindControl("lstActiveDocs"), ListBox))
             RadAjaxManager1.AjaxSettings.AddAjaxSetting(CType(MyUserControl.FindControl("btnAddDoc"), Button), _ 
                                                         CType(MyUserControl.FindControl("lstRelateDocs"), ListBox)) 
      End If 
   End If 
End Sub 

Sorry, but what can I do?

Thanks,
Liza
Tags
Grid
Asked by
Liza
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Liza
Top achievements
Rank 1
Share this question
or