Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1459
  • Last Modified:

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

Development Platform: c#, asp.net 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;
                DropDownList_StaffMembers.style.visibility = "hidden";   //this line is not compiling
            }
            else
            {
                RadioButton_Role.Checked = false;
                RadioButton_StaffMember.Checked = true;
                DropDownList_StaffMembers.style.visibility = 'visible';    //this line is not compiling
            }
        }


thank you in advance for your time and efforts with this enquiry.
0
amillyard
Asked:
amillyard
  • 3
  • 2
4 Solutions
 
strickddCommented:
try:

DropDownList_StaffMembers.style.setExpression("hidden", "true");
0
 
amillyardAuthor Commented:
@strickdd

I am getting the following compilier error as follows:

'System.Web.UI.WebControls.DropDownList' does not contain a definition for 'style'
0
 
dstanley9Commented:
Instead of

DropDownList_StaffMembers.style.visibility = "hidden";   //this line is not compiling

use

DropDownList_StaffMembers.Visible = false;

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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

Label1.Style["visibility"] = "hidden";
0
 
amillyardAuthor Commented:
@dstanley9

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">
                            </asp:DropDownList>
                        </td>
0
 
dstanley9Commented:
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.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now