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

Accessing Control in Form Template

4 Answers 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jpchenot
Top achievements
Rank 2
jpchenot asked on 03 Sep 2008, 09:18 PM
Hi.

I have a form template inside my radgrid.

On ItemDatabound, I would like to access a button in this form template in order to register it fot an asyncpostback with the scriptmanager. But I cannot find it.

Here is the code I use:

Protected Sub grMessages_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grMessages.ItemDataBound
        If TypeOf (e.Item) Is GridDataItem Then
            Dim messageID As Integer = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("MessageID")
            Dim senderID As Integer = DataBinder.Eval(e.Item.DataItem, "FromID")
            Dim read As String = DataBinder.Eval(e.Item.DataItem, "Read")

            Dim lblSender As Label = e.Item.FindControl("lblSender")

            Dim query = (From tbl In db.tbl_UserProfiles Where tbl.UserID = senderID _
                         Select tbl.UserName).FirstOrDefault

            lblSender.Text = query

            If read = "False" Then
                e.Item.Style.Add("font-weight", "bold")
            End If

        ElseIf TypeOf (e.Item) Is GridEditFormItem Then
            Dim btnInsert As ImageButton = e.Item.FindControl("btnInsert")

            If Not btnInsert Is Nothing Then
                Dim script As ScriptManager =     Master.FindControl("ScriptManager1")
                script.RegisterAsyncPostBackControl(btnInsert)
            End If
        End If
    End Sub


But the button always commes back as nothing.

Any help would be highly appreciated...

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Sep 2008, 04:52 AM
 
0
Shinu
Top achievements
Rank 2
answered on 04 Sep 2008, 04:57 AM
Hi Jean,

Here is the code I tried to access a button in the FormTemplate.

ASPX:
<EditFormSettings EditFormType="Template" > 
                 <FormTemplate> 
                     <asp:Button ID="Button4" runat="server" Text="Button" /> 
                  </FormTemplate> 
             </EditFormSettings> 

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            Button btn=(Button)editItem.FindControl("Button4"); 
         } 
   } 


Thanks
Shinu
0
jpchenot
Top achievements
Rank 2
answered on 04 Sep 2008, 08:07 AM
Thank you very much.

I was missing the check for the edit mode...
0
Princy
Top achievements
Rank 2
answered on 04 Sep 2008, 10:50 AM
Hi  Jean-Philippe,

You can also go through the following help articles toget details about EditForms and accessing controls from edit form.

Edit forms
Referring controls in FormTemplate

Thanks
Princy.

Tags
Grid
Asked by
jpchenot
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
jpchenot
Top achievements
Rank 2
Share this question
or