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

Get a reference to a control inside a RadGrid popup edit form

3 Answers 313 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 07 Nov 2012, 06:03 PM
I have a radgrid that uses a popup edit form. I want to get a reference to a checkbox that is on this edit form using javascript. How can I do this?

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Nov 2012, 04:18 AM
Hi Matt,

I guess you want to access a GridCheckBoxColumn in Edit form popup. Please take a look into the following code snippet I tried to access the CheckBoxColumn in an External Button Click.

ASPX:
<asp:Button ID="button1" runat="server" Text="Test" OnClientClick="ClientClick() ;return false"/>

C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
    {
        {
            GridEditableItem editForm = (GridEditableItem)e.Item;
            CheckBox chk = (CheckBox)(editForm["uniqueName"].Controls[0]);
            RadGrid1.Controls.Add(new LiteralControl("<script type='text/javascript'>window['check'] = '" + chk.ClientID + "';</script>"));
        }
    }
}

Javascript:
<script type="text/javascript">
    function ClientClick()
    {
        var EntityKeyName = document.getElementById(window['check']);
    }
</script>

Thanks,
Shinu.
0
Matt
Top achievements
Rank 1
answered on 08 Nov 2012, 03:14 PM
This isn't exactly what I was looking for. What I wanted to accomplish was include a checkbox in an edit popup form and on the click event, either disable or enable textboxes on the same edit form. I decided to create a UserControl in my edit form and do it all server side instead. Seems to be much easier with an acceptable sacrifice in performance.
Thanks anyway.
0
Shinu
Top achievements
Rank 2
answered on 09 Nov 2012, 04:57 AM
Hi,

You can access the controls in usercontrol from server side as shown below.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        GridEditFormItem editItem = (GridEditFormItem)e.Item;
        UserControl userControl = (UserControl)editItem.FindControl(GridEditFormItem.EditFormUserControlID);
        CheckBox chk = (CheckBox)userControl.FindControl("CheckBox1");
        chk.AutoPostBack = true;
        chk.CheckedChanged += new EventHandler(chk_CheckedChanged);
    }
}
void chk_CheckedChanged(object sender, EventArgs e)
{
    CheckBox chk = (CheckBox)sender;
    UserControl ctl = (UserControl)chk.NamingContainer;
    TextBox txt = (TextBox)ctl.FindControl("TextBox1");
    txt.Text = "your text";
}

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