Solved

Why is Menu1.CssClass doesnt work

Posted on 2008-10-14
3
250 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
[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
  • 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

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

627 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