c# asp using the .style.visibility server-side (aspx.cs)

Posted on 2007-10-18
Last Modified: 2013-12-17
Development Platform: c#, 2.x, Visual Studio Pro utilising Web Developer, IIS 6, SQL Server 2005

the following script line is working fine within the .aspx form, can make the DropDownList visible or hidden).

onclick="document.getElementById('DropDownList_StaffMembers').style.visibility = 'hidden';"

how do I perform this action from the server-side of things...i.e. inside a PreRender procedure?

        protected void Page_PreRender(object sender, EventArgs e)
            ViewState["_isChecked"] = RadioButton_Role.Checked;

            if (Convert.ToBoolean(ViewState["_isChecked"]))
                RadioButton_Role.Checked = true;
                RadioButton_StaffMember.Checked = false;
       = "hidden";   //this line is not compiling
                RadioButton_Role.Checked = false;
                RadioButton_StaffMember.Checked = true;
       = 'visible';    //this line is not compiling

thank you in advance for your time and efforts with this enquiry.
Question by:amillyard
    LVL 28

    Assisted Solution

    try:"hidden", "true");

    Author Comment


    I am getting the following compilier error as follows:

    'System.Web.UI.WebControls.DropDownList' does not contain a definition for 'style'
    LVL 25

    Accepted Solution

    Instead of = "hidden";   //this line is not compiling


    DropDownList_StaffMembers.Visible = false;

    LVL 25

    Assisted Solution

    Also, the style property works differently in code-behind that it does in JavaScript (which is interpreted rather than compiled)

    Label1.Style["visibility"] = "hidden";

    Author Comment


    yes, this certainly works ... but, when I click on the radio button again, it refuses to reappear -- I suspect its because the above visibility is the overall visibility control setting?

    below is the script I use on the form to hide and show the drop down list, depending on which radio button you select.

    as is stands now, when the page refreshes and gets pre-rendered, the drop down list now disappears and remains that way -- even with the radio button to select option again is used.

    your thoughts are much apprieated.

                            <td style="width: 366px">
                                <asp:RadioButton ID="RadioButton_Role" runat="server" Font-Size="X-Small" GroupName="PipelineSpoolerTask" Text="Role" onclick="document.getElementById('DropDownList_StaffMembers').style.visibility = 'hidden';"/>
                                <asp:RadioButton ID="RadioButton_StaffMember" runat="server" Font-Size="X-Small" GroupName="PipelineSpoolerTask" Text="Staff Member" onclick="document.getElementById('DropDownList_StaffMembers').style.visibility = 'visible';" Checked="True" />&nbsp;
                                <asp:DropDownList ID="DropDownList_StaffMembers" runat="server" DataSourceID="SqlDataSource_StaffMembers"
                                    DataTextField="DisplayName" DataValueField="CompanyAgent_ID">
    LVL 25

    Assisted Solution

    The code you had works on the server, not on the client.  You either need to

    1) Use JavaScript on the client to respond to the redio button click
    2) Set AutoPostBack to true on the radio button so that clicking it will cause a post-back, or
    3) Use AJAX controls that will do call-backs to execute your server-side code.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now