Radbutton returns null if made visible

3 posts, 0 answers
  1. Sachidanand
    Sachidanand avatar
    12 posts
    Member since:
    Jun 2011

    Posted 05 Apr 2012 Link to this post

    I am getting error while implement this supposedly very simple looking sceanrio using 2 radbutton.
    I have 2 rad buttons on the form as below.
    - First I wanted to set the property visiblity to false to one of them based on the session variable set.
    - & then alternate the visiblity between the 2 rad buttons when either one is clicked.

    The problem is as below. When I set the visiblity=false on click of one button. It works first time. On the next click (of the current visible button),I recieve an error, returns a null error while trying to make the previously made invisible buttom visible.

    <telerik:RadButton ID="rb1" runat="server" skin="Vista" Text="Switch to 2" 
    OnClientClicking="OnClick_1" OnClick="OnClicked_1" GroupName="GroupName1" ButtonType="ToggleButton" Visible="false"
    <telerik:RadButton ID="rb2" runat="server" skin="Vista" Text="Switch to 1" 
    OnClientClicking="OnClick_2" OnClick="OnClicked_2" GroupName="GroupName1" ButtonType="ToggleButton"
    If somebody can throw some light here please. I will really appreciate. Below is the code I am using to change the visibility.
    var radButton1 = $find("rb1"); 
    var radButton2 = $find("rb2"); 

    Note: There is a another conditional snippet which sets rb1 visiblity to false & rb2 to true.
    here rb2 is throwing null (because its visiblity is already set to false), the reason why throwign errror while setting the visibility to true.

    Thank you

  2. Sachidanand
    Sachidanand avatar
    12 posts
    Member since:
    Jun 2011

    Posted 05 Apr 2012 Link to this post

    To Update more. This works alright on the server side. The issue arrives if I want to perform this on the client side.
  3. DevCraft R3 2016 release webinar banner
  4. Slav
    Slav avatar
    1351 posts

    Posted 09 Apr 2012 Link to this post

    Hello Sachidanand,

    Note that a RadButton control will not be rendered on the page if its property Visible is set to false. As a result you will not be able to display it on the client-side. In case you want to switch the RadButton's visibility via JavaScript you should use client script to hide it when the page is initially loaded, which will ensure that it is rendered on the page and can be referenced. You can do so by setting the button control's visibility on page load via the client-side method set_visible:
    function pageLoad() {
        var radButton1 = $find("rb1");
    For your convenience I have attached a sample page that demonstrates the suggested approach. Please use it as a reference for your further development.

    All the best,
    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