Solved

hiding html li using c#

Posted on 2011-02-18
8
3,046 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 53

Expert Comment

by:Huseyin KAHRAMAN
ID: 34929712
try

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

Expert Comment

by:Huseyin KAHRAMAN
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 53

Expert Comment

by:Huseyin KAHRAMAN
ID: 34930198
ok, try this

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

or

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

Expert Comment

by:Huseyin KAHRAMAN
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check only one toolstripmenu item 12 62
Loading Self-Hosted Fonts 12 43
Check for Numeric Phone Field 14 48
Tell me if I understand this correctly... 6 20
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

751 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