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

Radbutton returns null if made visible

2 Answers 294 Views
Button
This is a migrated thread and some comments may be shown as answers.
Sachidanand
Top achievements
Rank 1
Sachidanand asked on 05 Apr 2012, 10:19 PM

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
  
<telerik:RadButton ID="rb2" runat="server" skin="Vista" Text="Switch to 1" 
OnClientClicking="OnClick_2" OnClick="OnClicked_2" GroupName="GroupName1" ButtonType="ToggleButton"
</telerik:RadButton>
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"); 
radButton1.set_visible(false);
  
var radButton2 = $find("rb2"); 
radButton1.set_visible(true);

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 Answers, 1 is accepted

Sort by
0
Sachidanand
Top achievements
Rank 1
answered on 05 Apr 2012, 10:40 PM
To Update more. This works alright on the server side. The issue arrives if I want to perform this on the client side.
0
Slav
Telerik team
answered on 09 Apr 2012, 11:50 AM
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");
    radButton1.set_visible(false);
}
 
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,
Slav
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.
Tags
Button
Asked by
Sachidanand
Top achievements
Rank 1
Answers by
Sachidanand
Top achievements
Rank 1
Slav
Telerik team
Share this question
or