Solved

Why is Menu1.CssClass doesnt work

Posted on 2008-10-14
3
242 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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 …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now