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

Visible/invisible

2 Answers 53 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Zed
Top achievements
Rank 1
Zed asked on 05 Aug 2008, 01:21 PM
I need to make a textbox invisible if a RadComboBox selected Index Changes to 2.   I cannot seem to attach this to the combo box:
  this.ddlStatus.Attributes.Add("onChange", "javascript:ToggleDisplay();");

2 Answers, 1 is accepted

Sort by
0
Accepted
Paul
Telerik team
answered on 05 Aug 2008, 01:40 PM
Hi Zed,

Please find below a sample code snippet that shows the needed approach.

ASPX:
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server">  
        <div> 
            <asp:ScriptManager ID="ScriptManager1" runat="server">  
            </asp:ScriptManager> 
        </div> 
        <telerik:RadCodeBlock runat="server">  
 
            <script type="text/javascript">  
            function ToggleVisibility(sender, eventArgs)  
            {  
                var item = eventArgs.get_item();  
                var tb = $get('<%= TextBox1.ClientID %>');  
                if(item.get_value() == "RadComboBoxItem2")  
                {  
                    tb.style.display = "none";  
                }     
                else  
                {  
                    tb.style.display = "block";  
                }  
            }  
            </script> 
 
        </telerik:RadCodeBlock> 
        <telerik:RadComboBox ID="RadComboBox1" runat="server">  
            <Items> 
                <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1" Value="RadComboBoxItem1" /> 
                <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2" Value="RadComboBoxItem2" /> 
                <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem3" Value="RadComboBoxItem3" /> 
            </Items> 
            <CollapseAnimation Duration="200" Type="OutQuint" /> 
        </telerik:RadComboBox> 
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
    </form> 
</body> 
</html> 

Code-behind:
using System;  
using System.Data;  
using System.Configuration;  
using System.Collections;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Web.UI.HtmlControls;  
 
public partial class _Default : System.Web.UI.Page  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        RadComboBox1.OnClientSelectedIndexChanged = "ToggleVisibility";  
    }  
}  
 


Regards,
Paul
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Zed
Top achievements
Rank 1
answered on 05 Aug 2008, 03:00 PM
Beautiful!!!
Tags
ComboBox
Asked by
Zed
Top achievements
Rank 1
Answers by
Paul
Telerik team
Zed
Top achievements
Rank 1
Share this question
or