Solved

Why is Menu1.CssClass doesnt work

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

20 Experts available now in Live!

Get 1:1 Help Now