Retrieving grid editor value client side

Thread is closed for posting
3 posts, 1 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 26 Jul 2006 Link to this post

     

    Requirements

    RadGrid for ASP .NET version

    RadControls for ASP .NET AJAX version

    3.5.1 and later


    2008.1.415 and later

    .NET version

    2.0 and later

    Visual Studio version

    2005 and later

    Programming language

    VB.NET, Javascript

    Browser support

    all supported by RadGrid for ASP .NET


    all browsers supported by RadControls for ASP .NET AJAX



    PROJECT DESCRIPTION

    The demo illustrates how to access the Country field editor value (pressing a button and wiring its onclick event) when item is in edit/insert mode. Note that we store the client id of the textbox editor in window object attribute (global scope variable) and then trace the textbox on the client calling the document.getElementById(id) javascript method.

    Note: the example uses WebUserControl custom edit form, however the same technique is applicable with for FormTemplate or auto-generated edit forms (with slight modifications in the code).

    Below is an the modification required when using FormTemplate custom edit form:

    Protected Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid1.ItemCreated  
            If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then 
                Dim editFormItem As GridEditFormItem = CType(e.Item, GridEditFormItem)  
                Dim box As TextBox = editFormItem.FindControl("TextBox1")  
                RadGrid1.Controls.Add(New LiteralControl("<script type='text/javascript'>window['CountryBoxId'] = '" & box.ClientID & "';</script>"))  
            End If 
    End Sub 
  2. Answer
    Ravi
    Ravi avatar
    13 posts
    Member since:
    Oct 2008

    Posted 22 Dec 2008 Link to this post

    i try the Examples but its not working javascript value throw null alert



    its my coding

    vb.net
    --------
    Protected Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid1.ItemCreated  
            If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then 
                Dim editFormItem As GridEditFormItem = CType(e.Item, GridEditFormItem)  
                Dim box As TextBox = editFormItem.FindControl("txtName")  
                RadGrid1.Controls.Add(New LiteralControl("<script type='text/javascript'>window['NameId'] = '" & box.ClientID & "';</script>"))  
            End If 
    End Sub 

    Javascript
    ------------
    <script language="javascript" type="text/javascript">
    function GetValue()
                {  
                  var Names= document.getElementById(window['NameId']);
                 
                  if(!Names)
                  {
                    alert("no item in edit/insert mode available");
                    return false;
                  }
                  else
                  { 
                    alert("Title edited value is: " + Names.value);
                  } 
                 
                }
    </script>



    aspx  custom  Editable grid
    --------

    <EditFormSettings  EditFormType="Template"  >
                                                <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                                                <FormCaptionStyle CssClass="RadGridHeader"></FormCaptionStyle>
                                                <FormMainTableStyle BackColor="White" GridLines="Horizontal" CellPadding="3" Width="100%" CellSpacing="0"></FormMainTableStyle>
                                                <FormTableStyle CellSpacing="0" CellPadding="2" CssClass="module" Height="110px" BackColor="White" />
                                                <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                                                <EditColumn CancelText="Cancel edit" InsertText="Insert Order"  UniqueName="EditCommandColumn1" ButtonType="ImageButton" UpdateText="Update record">
                                                </EditColumn>
                                                <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
                                                    <FormTemplate >
                                                        <table cellpadding="0"  cellspacing="0" width="100%" border="0">
                                                            <tr><td style="height:3px;" colspan ="2"></td></tr>
                                                            <tr>
                                                                <td align="right" colspan="2">
                                                                    <asp:ImageButton ID="btnUpdate" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>' ImageUrl="~/Images/icons/Update.gif"
                                                                    runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>' OnClientClick="return fn_GetValue()">
                                                                    </asp:ImageButton>&nbsp;
                                                                    <asp:ImageButton ID="Button1" Text="Cancel" runat="server" CausesValidation="False" ImageUrl="~/Images/icons/CancelEdit.gif"
                                                                    CommandName="Cancel" OnClientClick="DeleteHiddenvalue()"></asp:ImageButton>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td >
                                                                   <asp:TextBox ID="txtName" runat="server" EnableTheming ="true" Text='<%#Eval("name") %>' ></asp:TextBox>&nbsp;                  </td>
                                                          </tr>
                                              </table>
                     
                                                    </FormTemplate>
                                                </EditFormSettings>


    HELP ANY ONE ......THANKS







  3. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 22 Dec 2008 Link to this post

    Hello Ravi,

    Can you please verify that the demos attached to this code library thread work as expected on your machine? If you experience difficulties in converting the code for your particular configuration, pleaseĀ prepare a small working version of your project, illustrating the erroneous behavior, and send it attached to a formal support ticket. We will examine your complete code logic and will advice you further.

    Kind regards,
    Sebastian
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top