Accessing Control in Form Template

5 posts, 0 answers
  1. jpchenot
    jpchenot avatar
    20 posts
    Member since:
    Jan 2008

    Posted 03 Sep 2008 Link to this post

    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...
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Sep 2008 Link to this post

     
  3. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Sep 2008 Link to this post

    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
  4. jpchenot
    jpchenot avatar
    20 posts
    Member since:
    Jan 2008

    Posted 04 Sep 2008 Link to this post

    Thank you very much.

    I was missing the check for the edit mode...
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Sep 2008 Link to this post

    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.

Back to Top