Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

hiding html li using c#

Posted on 2011-02-18
8
Medium Priority
?
3,219 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
[X]
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
  • 4
  • 2
  • 2
8 Comments
 
LVL 59

Expert Comment

by:HainKurt
ID: 34929712
try

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

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
AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

 
LVL 59

Expert Comment

by:HainKurt
ID: 34930198
ok, try this

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

or

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

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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

671 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