Solved

Why is Menu1.CssClass doesnt work

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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