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

[Solved] Get Height of UserControl when used as the Edit Form in the RadGrid

2 Answers 196 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave Hollen
Top achievements
Rank 1
Dave Hollen asked on 12 Feb 2010, 07:29 PM
Hello,

I have a RadGrid that is using a User Control as the method of editing items in my grid. My question is, how can I get the height of the user control using Javascript?

I need the height so that I can set the ScrollArea property in java script.

Thanks,
Dave

2 Answers, 1 is accepted

Sort by
0
Dave Hollen
Top achievements
Rank 1
answered on 15 Feb 2010, 09:10 PM
Still struggling with this, any ideas?
0
Dimo
Telerik team
answered on 17 Feb 2010, 11:08 AM
Hi Dave,

User controls do not render a wrapper element of their own. In order to get the user control's height, you need to add some HTML element (e.g. asp:Panel) in the ASCX and include all the content in that element. Then you can get that element's height by using offsetHeight.


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<script runat="server">
 
    protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DataTable dt = new DataTable();
        DataRow dr;
        int colsNum = 4;
        int rowsNum = 5;
        string colName = "Column";
 
        for (int j = 1; j <= colsNum; j++)
        {
            dt.Columns.Add(String.Format("{0}{1}", colName, j));
        }
 
        for (int i = 1; i <= rowsNum; i++)
        {
            dr = dt.NewRow();
 
            for (int k = 1; k <= colsNum; k++)
            {
                dr[String.Format("{0}{1}", colName, k)] = String.Format("{0}{1} Row{2}", colName, k, i);
            }
            dt.Rows.Add(dr);
        }
 
        (sender as RadGrid).DataSource = dt;
    }
     
</script>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<head id="Head1" runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadGrid
    ID="RadGrid1"
    runat="server"
    Width="600px"
    AutoGenerateEditColumn="true"
    OnNeedDataSource="RadGrid_NeedDataSource">
    <MasterTableView EditMode="EditForms">
        <EditFormSettings EditFormType="WebUserControl" UserControlName="281499_grid.ascx" />
    </MasterTableView>
    <ClientSettings>
        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
        <ClientEvents OnGridCreated="GetUCHeight" />
    </ClientSettings>
</telerik:RadGrid>
 
<script type="text/javascript">
 
function GetUCHeight(sender, args)
{
    var editPanel = $telerik.getElementByClassName(sender.get_element(), "GridEditPanel", "div");
    if (editPanel)
        alert("The user control height is " + editPanel.offsetHeight + "px");
}
 
</script>
 
</form>
</body>
</html>



<%@ Control Language="C#" ClassName="_281499_grid" %>
 
<asp:Panel ID="Panel1" runat="server" CssClass="GridEditPanel">
 
RadGrid edit form content here
<br />
line 2
<br />
line3
 
</asp:Panel>



Greetings,
Dimo
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Dave Hollen
Top achievements
Rank 1
Answers by
Dave Hollen
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or