RadCodeBlock in User Control

2 posts, 0 answers
  1. Fatima
    Fatima avatar
    18 posts
    Member since:
    Aug 2012

    Posted 22 Oct 2012 Link to this post

    Hi
    I have a user control that contains some Rad-controls (RadComboBox, RadMenu, AjaxPanel, ...) and some javaScript methods and it works correctly.

    In my web site I need to use it in a panel that must be invisible at first page load, but unfortunately this property (visible = false) cause that user control's javascript isn't rendered and there are some errors about not finding javascript methods in the code page.

    My user control's javascript code is in RadCodeBlock.

    What is my solution?

    How can I have a user control that can be invisible at first and after showing, its scripts has no errors?


  2. Eyup
    Admin
    Eyup avatar
    4081 posts

    Posted 24 Oct 2012 Link to this post

    Hi Fatima,

    You could try the following approach:
    <asp:Button ID="Button1" runat="server" Text="Toggle Visibility" OnClientClick="toggleVisibility();" />
    <asp:HiddenField ID="HiddenField1" runat="server" Value="none" />
    <asp:Panel ID="Panel1" runat="server">
    JavaScript:
    function pageLoad() {
        $get("<%= Panel1.ClientID %>").style.display = $get("<%= HiddenField1.ClientID %>").value;
    }
    function toggleVisibility() {
        var value = $get("<%= HiddenField1.ClientID %>").value;
        $get("<%= HiddenField1.ClientID %>").value = value == "none" ? "" : "none";
    }

    I hope this will prove helpful. Please give it a try and let me know about the result.

    All the best,
    Eyup
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top