Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a drop down box which should be visible if a variable defined in my class file is true,else false.

What I have tried:

in my general.cs page
public static class myCommonvar

{

public static bool isVisible  
    {
        get
        {
            return false;
        }
    }
}

In the asp page where my asp.net control exists, I tried the below code
<asp:DropDownList ID="ddlcompanies"  runat="server" AutoPostBack="True"  Visible="<%# myCommonvar.isVisible %>"  >
										<asp:ListItem Value="0" class="menu-dropdown">View Clients</asp:ListItem>
										<asp:ListItem Value="1" class="menu-dropdown">in line clients/asp:ListItem>
										<asp:ListItem Value="2" class="menu-dropdown">Ext clients</asp:ListItem>
									</asp:DropDownList>


but not working
Can anyone help me please.
Posted
Updated 26-Oct-17 1:53am
Comments
Karthik_Mahalingam 26-Oct-17 6:20am    
since the property has only get parameter and it always returns false, there is no point of using the property. directly you can hardcode the visibility to false.
Member 10112611 26-Oct-17 6:27am    
Sorry,It is not like that I mean.. this cs page vary from client to client . Application will be same. For some clients isVisible will be true and some clients it will be false. Also I have 6 or 7 pages where i have to apply the visibility based on isVisible value.
Karthik_Mahalingam 26-Oct-17 21:24pm    
Use reply button to post comments so that the user gets notified

1 solution

The <%# %> syntax is for when the component is databound. As you are setting your list items manually the component is never being "bound", so you need to kick off the databinding in the code behind anyway for the visible property to work even though you don't need it for the listitems.

protected void Page_Load(object sender, EventArgs e)
{
    ddlcompanies.DataBind();
}


Also don't use static variables as they are shared across all users so if you set isVisible to a value then every person accessing the site sees it as that value and that might not be what you want.
 
Share this answer
 
Comments
Member 10112611 26-Oct-17 8:34am    
Thank you , it worked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900