Search code examples
telerikwidthradchart

How to set width in percents for Telerik RadChart for Asp.Net Ajax?


How can I resize the RadChart of Telerik for asp ajax to the full width of the screen?


Solution

  • This is what I came up with and it works fine for me

    C# code on the server

        public void buttonUpdate_Click(object sender, EventArgs args)
        {
            this.radChart1.Visible = true;
            this.radChart1.Width = Int32.Parse(this.hiddenFieldWidthInPixels.Value);
        }
    

    html and javascript on the client

    <asp:UpdatePanel runat="server" ID="updatePanel" OnLoad="wtf" UpdateMode="Conditional">
            <ContentTemplate>
                <panel>    
                    <asp:Button runat="server" ID="buttonUpdate" style="width:80%; height:10%; visibility: collapse; "  Text="This is the update button and should not be visible" OnClick="buttonUpdate_Click" /> 
                    <asp:HiddenField runat="server" ID="hiddenFieldWidthInPixels" /> 
                    <telerik:RadChart runat="server" ID="radChart1" Visible="false" />                         
                </panel>
            </ContentTemplate>
    </asp:UpdatePanel>
    
        <script type="text/javascript">
    
            function getASPElm(nm) {
                if ($get(nm)) return $get(nm);
    
                var e = document.getElementsByTagName('*');
                for (var i = 0; i < e.length; i++) {
                    if (e[i].id) {
                        if (e[i].id.indexOf(nm) != -1) return e[i];
                    }
                }
    
                return null;
                //http://forums.asp.net/t/1107047.aspx/1
            }
    
            var buttonUpdate = getASPElm('buttonUpdate');
            var hiddenField = getASPElm('hiddenFieldWidthInPixels');
            hiddenField.value = buttonUpdate.style.pixelWidth;
    
            buttonUpdate.click();
        </script>
    

    And I also found this link on Telerik's site with another approach link

    LaGrandMere, thanks for the help, but the provided link did not really address mu issue.