471,073 Members | 1,158 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

Navigation bar in asp.net

Hi,

I've created html websites before and used javascript
menus.

I'm now currently creating an aspx website. Is there a
way to write a simple navigation. e.g. mouseover a link
and get a list of navigation subitems. Can it also use
stylesheets? As you can tell, i'm a bit confused.

If anyone can point me in the right direction, i'd be
really grateful.

thank you.

Captain BirdsEye
Nov 17 '05 #1
2 3803
Captain Birds Eye,

An ASPNET application exist from a serverside application and a client side
userinterface which is handled by a browser.

There are two methods.
Where is in the aspx page a kind of scripting
Where is an aspx page that references to a dll

In both cases is that created page not returned to the browser. From the
ASPX page is a kind of HTML page created that includes JavaScript (or VBS).

You are able to add from your application JavaScript to that page. By
instance to controls with the attributes property or to add functions by the
page.registerstartupscript

However JavaScript is used on the client side (it is generated as well from
your application). Therefore when you want a menu, by instance created with
buttons, which change there colour or whatever when hoovering, than you have
to do that with JavaScript because the mouse is not on the serverside.

I hope this gives some idea's

Cor
Nov 17 '05 #2
4guysfromrolla ( http://www.4guysfromrolla.com ) have a good site with lots
of ASP.NET answers. They show how to make a rollover button which I used as
a basis for controls used on my company site at http://www.ramuseco.com.

I created a web control that is used as a navigation bar and used this same
control on all of the pages. I upgraded it a bit.

The rollover button emits javascript to the client which handles the
rolllover effects. I include it's source code after my signature.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

-----------------------------------------------------------------------------------------

/// <summary>

/// Summary description for RolloverButton1.

/// </summary>

[DefaultProperty("Text"),

ToolboxData("<{0}:RolloverButton runat=server></{0}:RolloverButton>")]

public class RolloverButton : System.Web.UI.WebControls.LinkButton

{

string _mouseOffUrl="";

string _selectedUrl="";

bool _selected;

[

Bindable(true),

Description("The image shown when the button is in a selected state."),

Category("Appearance")

]

public string SelectedUrl

{

get

{

return _selectedUrl;

}

set

{

_selectedUrl=value;

ViewState["SelectedUrl"]=value;

}

}

[

Bindable(true),

Description("When true this shows the selected image instead of the mouseoff
image"),

Category("Appearance")

]

public bool Selected

{

get

{

return _selected;

}

set

{

_selected=value;

if(value)

ViewState["MouseOffUrl"]=_selectedUrl;

else

ViewState["MouseOffUrl"]=_mouseOffUrl;

}

}

[

Bindable(true),

Description("The image shown when the mouse is not over the button"),

Category("Appearance")

]

public string MouseOffUrl

{

get{

return _mouseOffUrl;

}

set{

_mouseOffUrl=value;

ViewState["MouseOffUrl"]=value;

}

}

[

Bindable(true),

Description("The image shown when the mouse is over the button"),

Category("Appearance")

]

public string MouseOverUrl

{

get{

if(ViewState["MouseOverUrl"]==null)

return string.Empty;

return ViewState["MouseOverUrl"].ToString();

}

set{ViewState["MouseOverUrl"]=value;}

}

protected override void RenderContents(HtmlTextWriter writer)

{

if(this.MouseOffUrl!=string.Empty)

{

Image i=new Image();

i.Attributes["name"]=this.ClientID+"_img";

i.ImageUrl=this.MouseOffUrl;

i.AlternateText=this.Text;

i.ToolTip=this.ToolTip;

i.RenderControl(writer);

}

else

base.RenderContents (writer);

}

protected override void OnPreRender(EventArgs e)

{

if(ViewState["MouseOverUrl"]==null)

ViewState["MouseOverUrl"]="";

if(ViewState["MouseOffUrl"]==null)

ViewState["MouseOffUrl"]="";

if(ViewState["SelectedUrl"]==null)

ViewState["SelectedUrl"]="";

string ImageLoadScript = "RollOverBuilder"+this.ClientID;

string scriptBlock=string.Format(

"<script language=\"JavaScript\">\r\n"+

" <!--\r\n"+

" {0}_mouseoff = new Image();\r\n"+

" {0}_mouseoff.src = \"{1}\";\r\n"+

" {0}_mouseover = new Image();\r\n"+

" {0}_mouseover.src = \"{2}\";\r\n"+

" {0}_selected = new Image();\r\n"+

" {0}_selected.src = \"{3}\";\r\n"+

" // -->\r\n"+

"</script>",this.ClientID,ViewState["MouseOffUrl"].ToString(),ViewState["MouseOverUrl"].ToString(),ViewState["SelectedUrl"].ToString());

Page.RegisterClientScriptBlock(ImageLoadScript,scr iptBlock);

this.Attributes["onmouseover"]=string.Format("display('{0}_img',
{0}_mouseover)",this.ClientID);

this.Attributes["onmouseout"]=string.Format("display('{0}_img',
{0}_mouseoff)",this.ClientID);

if(!Page.IsStartupScriptRegistered("displayScript" ))

Page.RegisterStartupScript("displayScript",

"<script language=\"JavaScript\">\r\n"+

" <!--\r\n"+

" function display(imgName, imgUrl)\r\n"+

" {\r\n"+

" if(document.images && typeof imgUrl != 'undefined')\r\n"+

" document[imgName].src = imgUrl.src;\r\n"+

" }\r\n"+

" // -->\r\n"+

"</script>");
base.OnPreRender (e);

}

}
-----------------------------------------------------------------------------------------

"Captain BirdsEye" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
Hi,

I've created html websites before and used javascript
menus.

I'm now currently creating an aspx website. Is there a
way to write a simple navigation. e.g. mouseover a link
and get a list of navigation subitems. Can it also use
stylesheets? As you can tell, i'm a bit confused.

If anyone can point me in the right direction, i'd be
really grateful.

thank you.

Captain BirdsEye

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Dave Patton | last post: by
reply views Thread by Veli-Pekka Tštilš | last post: by
1 post views Thread by Robert Neville | last post: by
4 posts views Thread by Sandy.Pittendrigh | last post: by
28 posts views Thread by laredotornado | last post: by
10 posts views Thread by EA | last post: by
1 post views Thread by quartzy | last post: by
reply views Thread by emalcolm_FLA | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.