Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

hiding html li using c#

Posted on 2011-02-18
8
2,965 Views
Last Modified: 2013-12-17
I have a number of list items that are being used in a drop down menu.  Everything works fine but now I have to make 1 element visible or invisible based on a session variable.  The following is the element I am working with:
 <li id="hope" runat="server">
                <a href="tx-lonestar-landing.aspx">Cypress Lonestar Initiative</a>
                    <div>
                        <ul>
                            <li><a href="tx-lonestar1.aspx">Expanded Coverage</a></li>
                            <li><a href="tx-lonestar2.aspx">New Pricing Options</a></li>
                            <li><a href="tx-lonestar4.aspx">Enhanced Customer Service</a></li>
                            <li><a href="tx-lonestar5.aspx">New Incentives</a></li>
                        </ul>
                    </div>
                </li>
in the code behind, I put:
 protected System.Web.UI.HtmlControls.HtmlGenericControl hope;
        protected void Page_Load(object sender, EventArgs e)
        {
            hope.Visible = false;  
        }
I keep getting an error that I need to use the NEW keyword.  I don't see anyway to use it.  What is the code to do this.
0
Comment
Question by:fredstov
  • 4
  • 2
  • 2
8 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 34929712
try

hope.style.add("display","none");
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34929731
remove this line

protected System.Web.UI.HtmlControls.HtmlGenericControl hope;

your code should be ok just with

hope.Visible = false;
0
 

Author Comment

by:fredstov
ID: 34930127
Sorry, neither one of these items worked.  I did forget 1 item.  The li control is in a master page.  I have tried the items in the master page and in the main page and i get an error that 'hope does not exits in current context'.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 51

Expert Comment

by:HainKurt
ID: 34930198
ok, try this

Master.FindControl("hope").Visible = false;

or

Master.FindControl("hope").style.add("display","none");
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34930207
if it is in a contol in master then find container first:

Master.FindControl("ContentID").FindControl("hope").Visible = false;

or

Master.FindControl("ContentID").FindControl("hope").style.add("display","none");
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 34930209
Would something like this modification to your markup work? The "if" condition is rather psedocode, but should give you the idea.
<% if (Session["sessionKey"] == true) { %>
    <li id="hope" runat="server">
        <a href="tx-lonestar-landing.aspx">Cypress Lonestar Initiative</a>
        <div>
            <ul>
                <li><a href="tx-lonestar1.aspx">Expanded Coverage</a></li>
                <li><a href="tx-lonestar2.aspx">New Pricing Options</a></li>
                <li><a href="tx-lonestar4.aspx">Enhanced Customer Service</a></li>
                <li><a href="tx-lonestar5.aspx">New Incentives</a></li>
            </ul>
        </div>
    </li>
<% } %>

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34930219
P.S.

I forgot to, but you can remove the 'runat="server"' at that point, unless you need it for something else.
0
 

Author Closing Comment

by:fredstov
ID: 34954491
this worked great and is what I was looking for--thank you
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

861 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