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

Why is Menu1.CssClass doesnt work

Posted on 2008-10-14
3
245 Views
Last Modified: 2013-12-17
Hi Experts,
i have created a dynamic menu control, works but the cssclass does not seem to. here is my code. i dont understand, it works fine if the create it thru a aspx page, but does not work when creating thru codebehind.
Can some one point me where i am making the mistake.
Thanks i appreciate it.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
 
 
public partial class Menu_dynamic : System.Web.UI.Page
{
    protected Menu menu1;
 
    protected override void OnPreInit(EventArgs e)
    {
        menu1 = new System.Web.UI.WebControls.Menu();
        menu1.CssClass = "menubody";
        menu1.StaticMenuStyle.CssClass = "tab";
        menu1.StaticSelectedStyle.CssClass = "tab2";
        menu1.Orientation = Orientation.Horizontal;
        menu1.Items.Add(new MenuItem("Tab A", "0"));
        menu1.Items[0].Selected = true;
        
 
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
       
        Page.Controls.Add(menu1);
 
    }
 
    
}

Open in new window

0
Comment
Question by:niceoneishere
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
hakkekushou earned 500 total points
ID: 22711849
I would take a look at the output of both methods to determine if inline CSS (style="" as an HTML tag attribute) is not being added as they would have precedence of a CSS class.
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 22711911
Hello Sir,
nope as i said before it works if i add them thru aspx page. i just dont understand how come the same thing does not work when adding thru code behind

Thanks
0
 
LVL 1

Expert Comment

by:hakkekushou
ID: 22734423
I would try changing:

    protected override void OnPreInit(EventArgs e)

to this:

    protected void Page_Init(object sender, EventArgs e)

The reason being is that it is most likely pre-init is too early to set property values. However when it would be done in the ASPX it most likely handles the order of initialization in the engine differently the when it is defined in the code behind.

The ASPX page is not pre-compiled where as the code behind is. So they are definitely handled differently up to a certain level.
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

765 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