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

access RadGrid edit form control in javascript

1 Answer 345 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sofiene
Top achievements
Rank 1
Sofiene asked on 21 Mar 2012, 02:48 PM

Hi ,
i have a datagrid within an editform template . With the JavaScript function document.getElementById i can't access to form controls, may be because this id is generated automatically and is different for the id specified in a template .
There are ways to this access realization?

Thanks’ for reply

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Mar 2012, 10:54 AM
Hello Sofiene,

Try the following javascript to access controls in FormTemplate.
aspx:
<EditFormSettings EditFormType="Template">
   <FormTemplate>
     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
     <asp:Button ID="btn" Text="btn" runat="server" OnClientClick="GetValue();" />
   </FormTemplate>
</EditFormSettings>
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
 if ((e.Item is GridEditFormItem && e.Item.IsInEditMode))
 {
   GridEditFormItem editFormItem = (GridEditFormItem)e.Item;
   TextBox box = editFormItem.FindControl("TextBox1") as TextBox;
   RadGrid1.Controls.Add(new LiteralControl("<script type='text/javascript'>window['TextBoxId'] = '" + box.ClientID + "';</script>"));
 }
}
JS:
<script type="text/javascript">
 function GetValue()
 {
  var Names = document.getElementById(window['TextBoxId']);
  if (!Names)
  {
    alert("no item in edit/insert mode available");
    return false;
  }
  else
  {
    alert("Title edited value is: " + Names.value);
  }
}
</script>

Thanks,
Shinu.
Tags
Grid
Asked by
Sofiene
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or