472,791 Members | 1,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

All Menu Navigation

Hi there,

I was reading an article
(http://avenuea-razorfish.com/article...ion_Turbek.pdf) on
'all-menu navigation' and I'd like to try and implement this in my site.
Can anyone recommend how to get started?

Is there an Ajax control available for this or would more a basic javascript
work just as well. I'm assuming I just need a div element that is shown on
a mouse over, but I'm not sure how to go about aligning all of the sub menu
items etc?

Please help a newbie!

Best regards

John
Jan 22 '07 #1
3 2042
hi john,
i'm also interested in designing proper navigation for web sites with clean
markup. i don't like the built-in .net menu control because it generates
bloated markup.
although i haven't heard of the 'all-menu' before, i have implemented one
just like it recently. according to the all-menu description, it is fully
expanded all the time, i.e. static. in this case you would have no need for
ajax or javascript or dropdowns. my implementation below is static, pure
html, styled with css.
if you want to look at a sample, i have uploaded a test page to:
http://tim.mackey.ie/stuff/Sample_Menu.html. if you view the source you'll
see that it generates nice markup, feel free to use the styles etc as you
see fit.

i based the implementation on sample code from
http://www.asp.net/CSSAdapters/Menu.aspx, which shows how to create decent
HTML for a Menu control bound to a SiteMapDataSource. the example above is
dynamic/dropdown-based, but I wanted a static menu so i modified it. i
would recommend you follow the example mentioned above and get it integrated
into your site and working. i've included my modified version if you are
interested, you can just replace MenuAdapter.cs with the code below.
although it looks like a lot of code just to render a menu, it isn't really.
the internal code for the built-in asp.net menu control would look very
similar. it runs lightning fast for me anyway.

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Reflection;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.Adapters;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.Adapters;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public class WebControlAdapterExtender
{
private WebControl _adaptedControl = null;
public WebControl AdaptedControl
{
get
{
System.Diagnostics.Debug.Assert(_adaptedControl != null, "CSS
Friendly adapters internal error", "No control has been defined for the
adapter extender");
return _adaptedControl;
}
}

public bool AdapterEnabled
{
get
{
bool bReturn = true; // normally the adapters are enabled

// Individual controls can use the expando property called
AdapterEnabled
// as a way to turn the adapters off.
// <asp:TreeView runat="server" AdapterEnabled="false" />
if ((AdaptedControl != null) &&
(!String.IsNullOrEmpty(AdaptedControl.Attributes["AdapterEnabled"]))
&&
(AdaptedControl.Attributes["AdapterEnabled"].IndexOf("false",
StringComparison.OrdinalIgnoreCase) == 0))
{
bReturn = false;
}

return bReturn;
}
}

private bool _disableAutoAccessKey = false; // used when dealing with
things like read-only textboxes that should not have access keys
public bool AutoAccessKey
{
get
{
// Individual controls can use the expando property called
AdapterEnabled
// as a way to turn on/off the heurisitic for automatically
setting the AccessKey
// attribute in the rendered HTML. The default is shown below
in the initialization
// of the bReturn variable.
// <asp:TreeView runat="server" AutoAccessKey="false" />

bool bReturn = true; // by default, the adapter will make access
keys are available
if (_disableAutoAccessKey ||
((AdaptedControl != null) &&
(!String.IsNullOrEmpty(AdaptedControl.Attributes["AutoAccessKey"]))
&&
(AdaptedControl.Attributes["AutoAccessKey"].IndexOf("false",
StringComparison.OrdinalIgnoreCase) == 0)))
{
bReturn = false;
}

return bReturn;
}
}

public WebControlAdapterExtender(WebControl adaptedControl)
{
_adaptedControl = adaptedControl;
}

public void RaiseAdaptedEvent(string eventName, EventArgs e)
{
string attr = "OnAdapted" + eventName;
if ((AdaptedControl != null) &&
(!String.IsNullOrEmpty(AdaptedControl.Attributes[attr])))
{
string delegateName = AdaptedControl.Attributes[attr];
Control methodOwner = AdaptedControl.Parent;
MethodInfo method =
methodOwner.GetType().GetMethod(delegateName);
if (method == null)
{
methodOwner = AdaptedControl.Page;
method = methodOwner.GetType().GetMethod(delegateName);
}
if (method != null)
{
object[] args = new object[2];
args[0] = AdaptedControl;
args[1] = e;
method.Invoke(methodOwner, args);
}
}
}

public void RenderBeginTag(HtmlTextWriter writer, string cssClass)
{
string id = (AdaptedControl != null) ? AdaptedControl.ClientID : "";

if
(!String.IsNullOrEmpty(AdaptedControl.Attributes["CssSelectorClass"]))
{
WriteBeginDiv(writer,
AdaptedControl.Attributes["CssSelectorClass"], id);
id = "";
}

WriteBeginDiv(writer, cssClass, id);
}

public void RenderEndTag(HtmlTextWriter writer)
{
WriteEndDiv(writer);

if
(!String.IsNullOrEmpty(AdaptedControl.Attributes["CssSelectorClass"]))
{
WriteEndDiv(writer);
}
}

static public void RemoveProblemChildren(Control ctrl,
List<ControlRestorationInfostashedControls)
{
RemoveProblemTypes(ctrl.Controls, stashedControls);
}

static public void RemoveProblemTypes(ControlCollection coll,
List<ControlRestorationInfostashedControls)
{
foreach (Control ctrl in coll)
{
if
(typeof(RequiredFieldValidator).IsAssignableFrom(c trl.GetType()) ||
typeof(CompareValidator).IsAssignableFrom(ctrl.Get Type()) ||
typeof(RegularExpressionValidator).IsAssignableFro m(ctrl.GetType())
||
typeof(ValidationSummary).IsAssignableFrom(ctrl.Ge tType()))
{
ControlRestorationInfo cri = new
ControlRestorationInfo(ctrl, coll);
stashedControls.Add(cri);
coll.Remove(ctrl);
continue;
}

if (ctrl.HasControls())
{
RemoveProblemTypes(ctrl.Controls, stashedControls);
}
}
}

static public void RestoreProblemChildren(List<ControlRestorationInfo >
stashedControls)
{
foreach (ControlRestorationInfo cri in stashedControls)
{
cri.Restore();
}
}

public string MakeChildId(string postfix)
{
return AdaptedControl.ClientID + "_" + postfix;
}

static public string MakeNameFromId(string id)
{
string name = "";
for (int i=0; i<id.Length; i++)
{
char thisChar = id[i];
char prevChar = ((i - 1) -1) ? id[i - 1] : ' ';
char nextChar = ((i + 1) < id.Length) ? id[i + 1] : ' ';
if (thisChar == '_')
{
if (prevChar == '_')
{
name += "_";
}
else if (nextChar == '_')
{
name += "$_";
}
else
{
name += "$";
}
}
else
{
name += thisChar;
}
}
return name;
}

static public string MakeIdWithButtonType(string id, ButtonType type)
{
string idWithType = id;
switch (type)
{
case ButtonType.Button:
idWithType += "Button";
break;
case ButtonType.Image:
idWithType += "ImageButton";
break;
case ButtonType.Link:
idWithType += "LinkButton";
break;
}
return idWithType;
}

public string MakeChildName(string postfix)
{
return MakeNameFromId(MakeChildId(postfix));
}

static public void WriteBeginDiv(HtmlTextWriter writer, string
className, string id)
{
writer.WriteLine();
writer.WriteBeginTag("div");
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
if (!String.IsNullOrEmpty(id))
{
writer.WriteAttribute("id", id);
}
writer.Write(HtmlTextWriter.TagRightChar);
writer.Indent++;
}

static public void WriteEndDiv(HtmlTextWriter writer)
{
writer.Indent--;
writer.WriteLine();
writer.WriteEndTag("div");
}

static public void WriteSpan(HtmlTextWriter writer, string className,
string content)
{
if (!String.IsNullOrEmpty(content))
{
writer.WriteLine();
writer.WriteBeginTag("span");
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(content);
writer.WriteEndTag("span");
}
}

static public void WriteImage(HtmlTextWriter writer, string url, string
alt)
{
if (!String.IsNullOrEmpty(url))
{
writer.WriteLine();
writer.WriteBeginTag("img");
writer.WriteAttribute("src", url);
writer.WriteAttribute("alt", alt);
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}
}

static public void WriteLink(HtmlTextWriter writer, string className,
string url, string title, string content)
{
if ((!String.IsNullOrEmpty(url)) &&
(!String.IsNullOrEmpty(content)))
{
writer.WriteLine();
writer.WriteBeginTag("a");
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.WriteAttribute("href", url);
writer.WriteAttribute("title", title);
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(content);
writer.WriteEndTag("a");
}
}

// Can't be static because it uses MakeChildId
public void WriteLabel(HtmlTextWriter writer, string className, string
text, string forId)
{
if (!String.IsNullOrEmpty(text))
{
writer.WriteLine();
writer.WriteBeginTag("label");
writer.WriteAttribute("for", MakeChildId(forId));
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.Write(HtmlTextWriter.TagRightChar);

if (AutoAccessKey)
{
writer.WriteBeginTag("em");
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(text[0].ToString());
writer.WriteEndTag("em");
if (!String.IsNullOrEmpty(text))
{
writer.Write(text.Substring(1));
}
}
else
{
writer.Write(text);
}

writer.WriteEndTag("label");
}
}

// Can't be static because it uses MakeChildId
public void WriteTextBox(HtmlTextWriter writer, bool isPassword, string
labelClassName, string labelText, string inputClassName, string id, string
value)
{
WriteLabel(writer, labelClassName, labelText, id);

writer.WriteLine();
writer.WriteBeginTag("input");
writer.WriteAttribute("type", isPassword ? "password" : "text");
if (!String.IsNullOrEmpty(inputClassName))
{
writer.WriteAttribute("class", inputClassName);
}
writer.WriteAttribute("id", MakeChildId(id));
writer.WriteAttribute("name", MakeChildName(id));
writer.WriteAttribute("value", value);
if (AutoAccessKey && (!String.IsNullOrEmpty(labelText)))
{
writer.WriteAttribute("accesskey",
labelText[0].ToString().ToLower());
}

writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}

// Can't be static because it uses MakeChildId
public void WriteReadOnlyTextBox(HtmlTextWriter writer, string
labelClassName, string labelText, string inputClassName, string value)
{
bool oldDisableAutoAccessKey = _disableAutoAccessKey;
_disableAutoAccessKey = true;

WriteLabel(writer, labelClassName, labelText, "");

writer.WriteLine();
writer.WriteBeginTag("input");
writer.WriteAttribute("readonly", "readonly");
if (!String.IsNullOrEmpty(inputClassName))
{
writer.WriteAttribute("class", inputClassName);
}
writer.WriteAttribute("value", value);
writer.Write(HtmlTextWriter.SelfClosingTagEnd);

_disableAutoAccessKey = oldDisableAutoAccessKey;
}

// Can't be static because it uses MakeChildId
public void WriteCheckBox(HtmlTextWriter writer, string labelClassName,
string labelText, string inputClassName, string id, bool isChecked)
{
writer.WriteLine();
writer.WriteBeginTag("input");
writer.WriteAttribute("type", "checkbox");
if (!String.IsNullOrEmpty(inputClassName))
{
writer.WriteAttribute("class", inputClassName);
}
writer.WriteAttribute("id", MakeChildId(id));
writer.WriteAttribute("name", MakeChildName(id));
if (isChecked)
{
writer.WriteAttribute("checked", "checked");
}
if (AutoAccessKey && (!String.IsNullOrEmpty(labelText)))
{
writer.WriteAttribute("accesskey", labelText[0].ToString());
}
writer.Write(HtmlTextWriter.SelfClosingTagEnd);

WriteLabel(writer, labelClassName, labelText, id);
}

// Can't be static because it uses MakeChildId
public void WriteSubmit(HtmlTextWriter writer, ButtonType buttonType,
string className, string id, string imageUrl, string javascript, string
text)
{
writer.WriteLine();

string idWithType = id;

switch (buttonType)
{
case ButtonType.Button:
writer.WriteBeginTag("input");
writer.WriteAttribute("type", "submit");
writer.WriteAttribute("value", text);
idWithType += "Button";
break;
case ButtonType.Image:
writer.WriteBeginTag("input");
writer.WriteAttribute("type", "image");
writer.WriteAttribute("src", imageUrl);
idWithType += "ImageButton";
break;
case ButtonType.Link:
writer.WriteBeginTag("a");
idWithType += "LinkButton";
break;
}

if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.WriteAttribute("id", MakeChildId(idWithType));
writer.WriteAttribute("name", MakeChildName(idWithType));

if (!String.IsNullOrEmpty(javascript))
{
string pureJS = javascript;
if (pureJS.StartsWith("javascript:"))
{
pureJS = pureJS.Substring("javascript:".Length);
}
switch (buttonType)
{
case ButtonType.Button:
writer.WriteAttribute("onclick", pureJS);
break;
case ButtonType.Image:
writer.WriteAttribute("onclick", pureJS);
break;
case ButtonType.Link:
writer.WriteAttribute("href", javascript);
break;
}
}

if (buttonType == ButtonType.Link)
{
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(text);
writer.WriteEndTag("a");
}
else
{
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}
}

static public void WriteRequiredFieldValidator(HtmlTextWriter writer,
RequiredFieldValidator rfv, string className, string controlToValidate,
string msg)
{
if (rfv != null)
{
rfv.CssClass = className;
rfv.ControlToValidate = controlToValidate;
rfv.ErrorMessage = msg;
rfv.RenderControl(writer);
}
}

static public void WriteRegularExpressionValidator(HtmlTextWriter
writer, RegularExpressionValidator rev, string className, string
controlToValidate, string msg, string expression)
{
if (rev != null)
{
rev.CssClass = className;
rev.ControlToValidate = controlToValidate;
rev.ErrorMessage = msg;
rev.ValidationExpression = expression;
rev.RenderControl(writer);
}
}

static public void WriteCompareValidator(HtmlTextWriter writer,
CompareValidator cv, string className, string controlToValidate, string msg,
string controlToCompare)
{
if (cv != null)
{
cv.CssClass = className;
cv.ControlToValidate = controlToValidate;
cv.ErrorMessage = msg;
cv.ControlToCompare = controlToCompare;
cv.RenderControl(writer);
}
}

static public void WriteTargetAttribute(HtmlTextWriter writer, string
targetValue)
{
if ((writer != null) && (!String.IsNullOrEmpty(targetValue)))
{
// If the targetValue is _blank then we have an opportunity to
use attributes other than "target"
// which allows us to be compliant at the XHTML 1.1 Strict
level. Specifically, we can use a combination
// of "onclick" and "onkeypress" to achieve what we want to
achieve when we used to render
// target='blank'.
//
// If the targetValue is other than _blank then we fall back to
using the "target" attribute.
// This is a heuristic that can be refined over time.
if (targetValue.Equals("_blank",
StringComparison.OrdinalIgnoreCase))
{
string js = "window.open(this.href, '_blank', ''); return
false;";
writer.WriteAttribute("onclick", js);
writer.WriteAttribute("onkeypress", js);
}
else
{
writer.WriteAttribute("target", targetValue);
}
}
}
}

public class ControlRestorationInfo
{
private Control _ctrl = null;
public Control Control
{
get { return _ctrl; }
}

private ControlCollection _coll = null;
public ControlCollection Collection
{
get { return _coll; }
}

public bool IsValid
{
get { return (Control != null) && (Collection != null); }
}

public ControlRestorationInfo(Control ctrl, ControlCollection coll)
{
_ctrl = ctrl;
_coll = coll;
}

public void Restore()
{
if (IsValid)
{
_coll.Add(_ctrl);
}
}
}
hope you like it
tim

"John" <Jo************@AOL.netwrote in message
news:em*************@TK2MSFTNGP05.phx.gbl...
Hi there,

I was reading an article
(http://avenuea-razorfish.com/article...ion_Turbek.pdf)
on 'all-menu navigation' and I'd like to try and implement this in my
site. Can anyone recommend how to get started?

Is there an Ajax control available for this or would more a basic
javascript work just as well. I'm assuming I just need a div element that
is shown on a mouse over, but I'm not sure how to go about aligning all of
the sub menu items etc?

Please help a newbie!

Best regards

John
Jan 23 '07 #2
This is great. Thanks very much for your time Tim.

I like your example version as well, which certainly helps my understanding.
I'll also have a go with your c# code, which will be good practice as I'm
mainly vb.net at the moment.

Anyway, I think this will do perfectly. Thanks again.

Best regards

John

PS Have added your blog to my Netvibes collection!

"Tim Mackey" <ti********@community.nospamwrote in message
news:01**********************************@microsof t.com...
hi john,
i'm also interested in designing proper navigation for web sites with
clean markup. i don't like the built-in .net menu control because it
generates bloated markup.
although i haven't heard of the 'all-menu' before, i have implemented one
just like it recently. according to the all-menu description, it is fully
expanded all the time, i.e. static. in this case you would have no need
for ajax or javascript or dropdowns. my implementation below is static,
pure html, styled with css.
if you want to look at a sample, i have uploaded a test page to:
http://tim.mackey.ie/stuff/Sample_Menu.html. if you view the source
you'll see that it generates nice markup, feel free to use the styles etc
as you see fit.

i based the implementation on sample code from
http://www.asp.net/CSSAdapters/Menu.aspx, which shows how to create decent
HTML for a Menu control bound to a SiteMapDataSource. the example above
is dynamic/dropdown-based, but I wanted a static menu so i modified it. i
would recommend you follow the example mentioned above and get it
integrated into your site and working. i've included my modified version
if you are interested, you can just replace MenuAdapter.cs with the code
below. although it looks like a lot of code just to render a menu, it
isn't really. the internal code for the built-in asp.net menu control
would look very similar. it runs lightning fast for me anyway.

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Reflection;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.Adapters;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.Adapters;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public class WebControlAdapterExtender
{
private WebControl _adaptedControl = null;
public WebControl AdaptedControl
{
get
{
System.Diagnostics.Debug.Assert(_adaptedControl != null, "CSS
Friendly adapters internal error", "No control has been defined for the
adapter extender");
return _adaptedControl;
}
}

public bool AdapterEnabled
{
get
{
bool bReturn = true; // normally the adapters are enabled

// Individual controls can use the expando property called
AdapterEnabled
// as a way to turn the adapters off.
// <asp:TreeView runat="server" AdapterEnabled="false" />
if ((AdaptedControl != null) &&

(!String.IsNullOrEmpty(AdaptedControl.Attributes["AdapterEnabled"])) &&

(AdaptedControl.Attributes["AdapterEnabled"].IndexOf("false",
StringComparison.OrdinalIgnoreCase) == 0))
{
bReturn = false;
}

return bReturn;
}
}

private bool _disableAutoAccessKey = false; // used when dealing with
things like read-only textboxes that should not have access keys
public bool AutoAccessKey
{
get
{
// Individual controls can use the expando property called
AdapterEnabled
// as a way to turn on/off the heurisitic for automatically
setting the AccessKey
// attribute in the rendered HTML. The default is shown below
in the initialization
// of the bReturn variable.
// <asp:TreeView runat="server" AutoAccessKey="false" />

bool bReturn = true; // by default, the adapter will make
access keys are available
if (_disableAutoAccessKey ||
((AdaptedControl != null) &&

(!String.IsNullOrEmpty(AdaptedControl.Attributes["AutoAccessKey"])) &&

(AdaptedControl.Attributes["AutoAccessKey"].IndexOf("false",
StringComparison.OrdinalIgnoreCase) == 0)))
{
bReturn = false;
}

return bReturn;
}
}

public WebControlAdapterExtender(WebControl adaptedControl)
{
_adaptedControl = adaptedControl;
}

public void RaiseAdaptedEvent(string eventName, EventArgs e)
{
string attr = "OnAdapted" + eventName;
if ((AdaptedControl != null) &&
(!String.IsNullOrEmpty(AdaptedControl.Attributes[attr])))
{
string delegateName = AdaptedControl.Attributes[attr];
Control methodOwner = AdaptedControl.Parent;
MethodInfo method =
methodOwner.GetType().GetMethod(delegateName);
if (method == null)
{
methodOwner = AdaptedControl.Page;
method = methodOwner.GetType().GetMethod(delegateName);
}
if (method != null)
{
object[] args = new object[2];
args[0] = AdaptedControl;
args[1] = e;
method.Invoke(methodOwner, args);
}
}
}

public void RenderBeginTag(HtmlTextWriter writer, string cssClass)
{
string id = (AdaptedControl != null) ? AdaptedControl.ClientID :
"";

if
(!String.IsNullOrEmpty(AdaptedControl.Attributes["CssSelectorClass"]))
{
WriteBeginDiv(writer,
AdaptedControl.Attributes["CssSelectorClass"], id);
id = "";
}

WriteBeginDiv(writer, cssClass, id);
}

public void RenderEndTag(HtmlTextWriter writer)
{
WriteEndDiv(writer);

if
(!String.IsNullOrEmpty(AdaptedControl.Attributes["CssSelectorClass"]))
{
WriteEndDiv(writer);
}
}

static public void RemoveProblemChildren(Control ctrl,
List<ControlRestorationInfostashedControls)
{
RemoveProblemTypes(ctrl.Controls, stashedControls);
}

static public void RemoveProblemTypes(ControlCollection coll,
List<ControlRestorationInfostashedControls)
{
foreach (Control ctrl in coll)
{
if
(typeof(RequiredFieldValidator).IsAssignableFrom(c trl.GetType()) ||
typeof(CompareValidator).IsAssignableFrom(ctrl.Get Type())
||

typeof(RegularExpressionValidator).IsAssignableFro m(ctrl.GetType()) ||
typeof(ValidationSummary).IsAssignableFrom(ctrl.Ge tType()))
{
ControlRestorationInfo cri = new
ControlRestorationInfo(ctrl, coll);
stashedControls.Add(cri);
coll.Remove(ctrl);
continue;
}

if (ctrl.HasControls())
{
RemoveProblemTypes(ctrl.Controls, stashedControls);
}
}
}

static public void RestoreProblemChildren(List<ControlRestorationInfo >
stashedControls)
{
foreach (ControlRestorationInfo cri in stashedControls)
{
cri.Restore();
}
}

public string MakeChildId(string postfix)
{
return AdaptedControl.ClientID + "_" + postfix;
}

static public string MakeNameFromId(string id)
{
string name = "";
for (int i=0; i<id.Length; i++)
{
char thisChar = id[i];
char prevChar = ((i - 1) -1) ? id[i - 1] : ' ';
char nextChar = ((i + 1) < id.Length) ? id[i + 1] : ' ';
if (thisChar == '_')
{
if (prevChar == '_')
{
name += "_";
}
else if (nextChar == '_')
{
name += "$_";
}
else
{
name += "$";
}
}
else
{
name += thisChar;
}
}
return name;
}

static public string MakeIdWithButtonType(string id, ButtonType type)
{
string idWithType = id;
switch (type)
{
case ButtonType.Button:
idWithType += "Button";
break;
case ButtonType.Image:
idWithType += "ImageButton";
break;
case ButtonType.Link:
idWithType += "LinkButton";
break;
}
return idWithType;
}

public string MakeChildName(string postfix)
{
return MakeNameFromId(MakeChildId(postfix));
}

static public void WriteBeginDiv(HtmlTextWriter writer, string
className, string id)
{
writer.WriteLine();
writer.WriteBeginTag("div");
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
if (!String.IsNullOrEmpty(id))
{
writer.WriteAttribute("id", id);
}
writer.Write(HtmlTextWriter.TagRightChar);
writer.Indent++;
}

static public void WriteEndDiv(HtmlTextWriter writer)
{
writer.Indent--;
writer.WriteLine();
writer.WriteEndTag("div");
}

static public void WriteSpan(HtmlTextWriter writer, string className,
string content)
{
if (!String.IsNullOrEmpty(content))
{
writer.WriteLine();
writer.WriteBeginTag("span");
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(content);
writer.WriteEndTag("span");
}
}

static public void WriteImage(HtmlTextWriter writer, string url, string
alt)
{
if (!String.IsNullOrEmpty(url))
{
writer.WriteLine();
writer.WriteBeginTag("img");
writer.WriteAttribute("src", url);
writer.WriteAttribute("alt", alt);
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}
}

static public void WriteLink(HtmlTextWriter writer, string className,
string url, string title, string content)
{
if ((!String.IsNullOrEmpty(url)) &&
(!String.IsNullOrEmpty(content)))
{
writer.WriteLine();
writer.WriteBeginTag("a");
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.WriteAttribute("href", url);
writer.WriteAttribute("title", title);
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(content);
writer.WriteEndTag("a");
}
}

// Can't be static because it uses MakeChildId
public void WriteLabel(HtmlTextWriter writer, string className, string
text, string forId)
{
if (!String.IsNullOrEmpty(text))
{
writer.WriteLine();
writer.WriteBeginTag("label");
writer.WriteAttribute("for", MakeChildId(forId));
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.Write(HtmlTextWriter.TagRightChar);

if (AutoAccessKey)
{
writer.WriteBeginTag("em");
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(text[0].ToString());
writer.WriteEndTag("em");
if (!String.IsNullOrEmpty(text))
{
writer.Write(text.Substring(1));
}
}
else
{
writer.Write(text);
}

writer.WriteEndTag("label");
}
}

// Can't be static because it uses MakeChildId
public void WriteTextBox(HtmlTextWriter writer, bool isPassword, string
labelClassName, string labelText, string inputClassName, string id, string
value)
{
WriteLabel(writer, labelClassName, labelText, id);

writer.WriteLine();
writer.WriteBeginTag("input");
writer.WriteAttribute("type", isPassword ? "password" : "text");
if (!String.IsNullOrEmpty(inputClassName))
{
writer.WriteAttribute("class", inputClassName);
}
writer.WriteAttribute("id", MakeChildId(id));
writer.WriteAttribute("name", MakeChildName(id));
writer.WriteAttribute("value", value);
if (AutoAccessKey && (!String.IsNullOrEmpty(labelText)))
{
writer.WriteAttribute("accesskey",
labelText[0].ToString().ToLower());
}

writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}

// Can't be static because it uses MakeChildId
public void WriteReadOnlyTextBox(HtmlTextWriter writer, string
labelClassName, string labelText, string inputClassName, string value)
{
bool oldDisableAutoAccessKey = _disableAutoAccessKey;
_disableAutoAccessKey = true;

WriteLabel(writer, labelClassName, labelText, "");

writer.WriteLine();
writer.WriteBeginTag("input");
writer.WriteAttribute("readonly", "readonly");
if (!String.IsNullOrEmpty(inputClassName))
{
writer.WriteAttribute("class", inputClassName);
}
writer.WriteAttribute("value", value);
writer.Write(HtmlTextWriter.SelfClosingTagEnd);

_disableAutoAccessKey = oldDisableAutoAccessKey;
}

// Can't be static because it uses MakeChildId
public void WriteCheckBox(HtmlTextWriter writer, string labelClassName,
string labelText, string inputClassName, string id, bool isChecked)
{
writer.WriteLine();
writer.WriteBeginTag("input");
writer.WriteAttribute("type", "checkbox");
if (!String.IsNullOrEmpty(inputClassName))
{
writer.WriteAttribute("class", inputClassName);
}
writer.WriteAttribute("id", MakeChildId(id));
writer.WriteAttribute("name", MakeChildName(id));
if (isChecked)
{
writer.WriteAttribute("checked", "checked");
}
if (AutoAccessKey && (!String.IsNullOrEmpty(labelText)))
{
writer.WriteAttribute("accesskey", labelText[0].ToString());
}
writer.Write(HtmlTextWriter.SelfClosingTagEnd);

WriteLabel(writer, labelClassName, labelText, id);
}

// Can't be static because it uses MakeChildId
public void WriteSubmit(HtmlTextWriter writer, ButtonType buttonType,
string className, string id, string imageUrl, string javascript, string
text)
{
writer.WriteLine();

string idWithType = id;

switch (buttonType)
{
case ButtonType.Button:
writer.WriteBeginTag("input");
writer.WriteAttribute("type", "submit");
writer.WriteAttribute("value", text);
idWithType += "Button";
break;
case ButtonType.Image:
writer.WriteBeginTag("input");
writer.WriteAttribute("type", "image");
writer.WriteAttribute("src", imageUrl);
idWithType += "ImageButton";
break;
case ButtonType.Link:
writer.WriteBeginTag("a");
idWithType += "LinkButton";
break;
}

if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.WriteAttribute("id", MakeChildId(idWithType));
writer.WriteAttribute("name", MakeChildName(idWithType));

if (!String.IsNullOrEmpty(javascript))
{
string pureJS = javascript;
if (pureJS.StartsWith("javascript:"))
{
pureJS = pureJS.Substring("javascript:".Length);
}
switch (buttonType)
{
case ButtonType.Button:
writer.WriteAttribute("onclick", pureJS);
break;
case ButtonType.Image:
writer.WriteAttribute("onclick", pureJS);
break;
case ButtonType.Link:
writer.WriteAttribute("href", javascript);
break;
}
}

if (buttonType == ButtonType.Link)
{
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(text);
writer.WriteEndTag("a");
}
else
{
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}
}

static public void WriteRequiredFieldValidator(HtmlTextWriter writer,
RequiredFieldValidator rfv, string className, string controlToValidate,
string msg)
{
if (rfv != null)
{
rfv.CssClass = className;
rfv.ControlToValidate = controlToValidate;
rfv.ErrorMessage = msg;
rfv.RenderControl(writer);
}
}

static public void WriteRegularExpressionValidator(HtmlTextWriter
writer, RegularExpressionValidator rev, string className, string
controlToValidate, string msg, string expression)
{
if (rev != null)
{
rev.CssClass = className;
rev.ControlToValidate = controlToValidate;
rev.ErrorMessage = msg;
rev.ValidationExpression = expression;
rev.RenderControl(writer);
}
}

static public void WriteCompareValidator(HtmlTextWriter writer,
CompareValidator cv, string className, string controlToValidate, string
msg, string controlToCompare)
{
if (cv != null)
{
cv.CssClass = className;
cv.ControlToValidate = controlToValidate;
cv.ErrorMessage = msg;
cv.ControlToCompare = controlToCompare;
cv.RenderControl(writer);
}
}

static public void WriteTargetAttribute(HtmlTextWriter writer, string
targetValue)
{
if ((writer != null) && (!String.IsNullOrEmpty(targetValue)))
{
// If the targetValue is _blank then we have an opportunity to
use attributes other than "target"
// which allows us to be compliant at the XHTML 1.1 Strict
level. Specifically, we can use a combination
// of "onclick" and "onkeypress" to achieve what we want to
achieve when we used to render
// target='blank'.
//
// If the targetValue is other than _blank then we fall back
to using the "target" attribute.
// This is a heuristic that can be refined over time.
if (targetValue.Equals("_blank",
StringComparison.OrdinalIgnoreCase))
{
string js = "window.open(this.href, '_blank', ''); return
false;";
writer.WriteAttribute("onclick", js);
writer.WriteAttribute("onkeypress", js);
}
else
{
writer.WriteAttribute("target", targetValue);
}
}
}
}

public class ControlRestorationInfo
{
private Control _ctrl = null;
public Control Control
{
get { return _ctrl; }
}

private ControlCollection _coll = null;
public ControlCollection Collection
{
get { return _coll; }
}

public bool IsValid
{
get { return (Control != null) && (Collection != null); }
}

public ControlRestorationInfo(Control ctrl, ControlCollection coll)
{
_ctrl = ctrl;
_coll = coll;
}

public void Restore()
{
if (IsValid)
{
_coll.Add(_ctrl);
}
}
}
hope you like it
tim

"John" <Jo************@AOL.netwrote in message
news:em*************@TK2MSFTNGP05.phx.gbl...
>Hi there,

I was reading an article
(http://avenuea-razorfish.com/article...ion_Turbek.pdf)
on 'all-menu navigation' and I'd like to try and implement this in my
site. Can anyone recommend how to get started?

Is there an Ajax control available for this or would more a basic
javascript work just as well. I'm assuming I just need a div element
that is shown on a mouse over, but I'm not sure how to go about aligning
all of the sub menu items etc?

Please help a newbie!

Best regards

John

Jan 23 '07 #3
great, glad to be of help.
i haven't the time to convert it to VB but i understand there are freely
available VB/C# conversion tools which should do most if not all of the work
for you. could come in handy if you regularly come across C# code that you
would prefer to use in vb.
good luck
tim
"John" <Jo************@AOL.netwrote in message
news:O4**************@TK2MSFTNGP06.phx.gbl...
This is great. Thanks very much for your time Tim.

I like your example version as well, which certainly helps my
understanding. I'll also have a go with your c# code, which will be good
practice as I'm mainly vb.net at the moment.

Anyway, I think this will do perfectly. Thanks again.

Best regards

John

PS Have added your blog to my Netvibes collection!

"Tim Mackey" <ti********@community.nospamwrote in message
news:01**********************************@microsof t.com...
>hi john,
i'm also interested in designing proper navigation for web sites with
clean markup. i don't like the built-in .net menu control because it
generates bloated markup.
although i haven't heard of the 'all-menu' before, i have implemented one
just like it recently. according to the all-menu description, it is
fully expanded all the time, i.e. static. in this case you would have no
need for ajax or javascript or dropdowns. my implementation below is
static, pure html, styled with css.
if you want to look at a sample, i have uploaded a test page to:
http://tim.mackey.ie/stuff/Sample_Menu.html. if you view the source
you'll see that it generates nice markup, feel free to use the styles etc
as you see fit.

i based the implementation on sample code from
http://www.asp.net/CSSAdapters/Menu.aspx, which shows how to create
decent HTML for a Menu control bound to a SiteMapDataSource. the example
above is dynamic/dropdown-based, but I wanted a static menu so i modified
it. i would recommend you follow the example mentioned above and get it
integrated into your site and working. i've included my modified version
if you are interested, you can just replace MenuAdapter.cs with the code
below. although it looks like a lot of code just to render a menu, it
isn't really. the internal code for the built-in asp.net menu control
would look very similar. it runs lightning fast for me anyway.

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Reflection;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.Adapters;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.Adapters;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public class WebControlAdapterExtender
{
private WebControl _adaptedControl = null;
public WebControl AdaptedControl
{
get
{
System.Diagnostics.Debug.Assert(_adaptedControl != null, "CSS
Friendly adapters internal error", "No control has been defined for the
adapter extender");
return _adaptedControl;
}
}

public bool AdapterEnabled
{
get
{
bool bReturn = true; // normally the adapters are enabled

// Individual controls can use the expando property called
AdapterEnabled
// as a way to turn the adapters off.
// <asp:TreeView runat="server" AdapterEnabled="false" />
if ((AdaptedControl != null) &&

(!String.IsNullOrEmpty(AdaptedControl.Attribute s["AdapterEnabled"])) &&

(AdaptedControl.Attributes["AdapterEnabled"].IndexOf("false",
StringComparison.OrdinalIgnoreCase) == 0))
{
bReturn = false;
}

return bReturn;
}
}

private bool _disableAutoAccessKey = false; // used when dealing with
things like read-only textboxes that should not have access keys
public bool AutoAccessKey
{
get
{
// Individual controls can use the expando property called
AdapterEnabled
// as a way to turn on/off the heurisitic for automatically
setting the AccessKey
// attribute in the rendered HTML. The default is shown
below in the initialization
// of the bReturn variable.
// <asp:TreeView runat="server" AutoAccessKey="false" />

bool bReturn = true; // by default, the adapter will make
access keys are available
if (_disableAutoAccessKey ||
((AdaptedControl != null) &&

(!String.IsNullOrEmpty(AdaptedControl.Attribute s["AutoAccessKey"])) &&

(AdaptedControl.Attributes["AutoAccessKey"].IndexOf("false",
StringComparison.OrdinalIgnoreCase) == 0)))
{
bReturn = false;
}

return bReturn;
}
}

public WebControlAdapterExtender(WebControl adaptedControl)
{
_adaptedControl = adaptedControl;
}

public void RaiseAdaptedEvent(string eventName, EventArgs e)
{
string attr = "OnAdapted" + eventName;
if ((AdaptedControl != null) &&
(!String.IsNullOrEmpty(AdaptedControl.Attribute s[attr])))
{
string delegateName = AdaptedControl.Attributes[attr];
Control methodOwner = AdaptedControl.Parent;
MethodInfo method =
methodOwner.GetType().GetMethod(delegateName);
if (method == null)
{
methodOwner = AdaptedControl.Page;
method = methodOwner.GetType().GetMethod(delegateName);
}
if (method != null)
{
object[] args = new object[2];
args[0] = AdaptedControl;
args[1] = e;
method.Invoke(methodOwner, args);
}
}
}

public void RenderBeginTag(HtmlTextWriter writer, string cssClass)
{
string id = (AdaptedControl != null) ? AdaptedControl.ClientID :
"";

if
(!String.IsNullOrEmpty(AdaptedControl.Attribute s["CssSelectorClass"]))
{
WriteBeginDiv(writer,
AdaptedControl.Attributes["CssSelectorClass"], id);
id = "";
}

WriteBeginDiv(writer, cssClass, id);
}

public void RenderEndTag(HtmlTextWriter writer)
{
WriteEndDiv(writer);

if
(!String.IsNullOrEmpty(AdaptedControl.Attribute s["CssSelectorClass"]))
{
WriteEndDiv(writer);
}
}

static public void RemoveProblemChildren(Control ctrl,
List<ControlRestorationInfostashedControls)
{
RemoveProblemTypes(ctrl.Controls, stashedControls);
}

static public void RemoveProblemTypes(ControlCollection coll,
List<ControlRestorationInfostashedControls)
{
foreach (Control ctrl in coll)
{
if
(typeof(RequiredFieldValidator).IsAssignableFrom( ctrl.GetType()) ||
typeof(CompareValidator).IsAssignableFrom(ctrl.Get Type())
||

typeof(RegularExpressionValidator).IsAssignableFr om(ctrl.GetType()) ||

typeof(ValidationSummary).IsAssignableFrom(ctrl.G etType()))
{
ControlRestorationInfo cri = new
ControlRestorationInfo(ctrl, coll);
stashedControls.Add(cri);
coll.Remove(ctrl);
continue;
}

if (ctrl.HasControls())
{
RemoveProblemTypes(ctrl.Controls, stashedControls);
}
}
}

static public void RestoreProblemChildren(List<ControlRestorationInfo >
stashedControls)
{
foreach (ControlRestorationInfo cri in stashedControls)
{
cri.Restore();
}
}

public string MakeChildId(string postfix)
{
return AdaptedControl.ClientID + "_" + postfix;
}

static public string MakeNameFromId(string id)
{
string name = "";
for (int i=0; i<id.Length; i++)
{
char thisChar = id[i];
char prevChar = ((i - 1) -1) ? id[i - 1] : ' ';
char nextChar = ((i + 1) < id.Length) ? id[i + 1] : ' ';
if (thisChar == '_')
{
if (prevChar == '_')
{
name += "_";
}
else if (nextChar == '_')
{
name += "$_";
}
else
{
name += "$";
}
}
else
{
name += thisChar;
}
}
return name;
}

static public string MakeIdWithButtonType(string id, ButtonType type)
{
string idWithType = id;
switch (type)
{
case ButtonType.Button:
idWithType += "Button";
break;
case ButtonType.Image:
idWithType += "ImageButton";
break;
case ButtonType.Link:
idWithType += "LinkButton";
break;
}
return idWithType;
}

public string MakeChildName(string postfix)
{
return MakeNameFromId(MakeChildId(postfix));
}

static public void WriteBeginDiv(HtmlTextWriter writer, string
className, string id)
{
writer.WriteLine();
writer.WriteBeginTag("div");
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
if (!String.IsNullOrEmpty(id))
{
writer.WriteAttribute("id", id);
}
writer.Write(HtmlTextWriter.TagRightChar);
writer.Indent++;
}

static public void WriteEndDiv(HtmlTextWriter writer)
{
writer.Indent--;
writer.WriteLine();
writer.WriteEndTag("div");
}

static public void WriteSpan(HtmlTextWriter writer, string className,
string content)
{
if (!String.IsNullOrEmpty(content))
{
writer.WriteLine();
writer.WriteBeginTag("span");
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(content);
writer.WriteEndTag("span");
}
}

static public void WriteImage(HtmlTextWriter writer, string url,
string alt)
{
if (!String.IsNullOrEmpty(url))
{
writer.WriteLine();
writer.WriteBeginTag("img");
writer.WriteAttribute("src", url);
writer.WriteAttribute("alt", alt);
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}
}

static public void WriteLink(HtmlTextWriter writer, string className,
string url, string title, string content)
{
if ((!String.IsNullOrEmpty(url)) &&
(!String.IsNullOrEmpty(content)))
{
writer.WriteLine();
writer.WriteBeginTag("a");
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.WriteAttribute("href", url);
writer.WriteAttribute("title", title);
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(content);
writer.WriteEndTag("a");
}
}

// Can't be static because it uses MakeChildId
public void WriteLabel(HtmlTextWriter writer, string className, string
text, string forId)
{
if (!String.IsNullOrEmpty(text))
{
writer.WriteLine();
writer.WriteBeginTag("label");
writer.WriteAttribute("for", MakeChildId(forId));
if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.Write(HtmlTextWriter.TagRightChar);

if (AutoAccessKey)
{
writer.WriteBeginTag("em");
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(text[0].ToString());
writer.WriteEndTag("em");
if (!String.IsNullOrEmpty(text))
{
writer.Write(text.Substring(1));
}
}
else
{
writer.Write(text);
}

writer.WriteEndTag("label");
}
}

// Can't be static because it uses MakeChildId
public void WriteTextBox(HtmlTextWriter writer, bool isPassword,
string labelClassName, string labelText, string inputClassName, string
id, string value)
{
WriteLabel(writer, labelClassName, labelText, id);

writer.WriteLine();
writer.WriteBeginTag("input");
writer.WriteAttribute("type", isPassword ? "password" : "text");
if (!String.IsNullOrEmpty(inputClassName))
{
writer.WriteAttribute("class", inputClassName);
}
writer.WriteAttribute("id", MakeChildId(id));
writer.WriteAttribute("name", MakeChildName(id));
writer.WriteAttribute("value", value);
if (AutoAccessKey && (!String.IsNullOrEmpty(labelText)))
{
writer.WriteAttribute("accesskey",
labelText[0].ToString().ToLower());
}

writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}

// Can't be static because it uses MakeChildId
public void WriteReadOnlyTextBox(HtmlTextWriter writer, string
labelClassName, string labelText, string inputClassName, string value)
{
bool oldDisableAutoAccessKey = _disableAutoAccessKey;
_disableAutoAccessKey = true;

WriteLabel(writer, labelClassName, labelText, "");

writer.WriteLine();
writer.WriteBeginTag("input");
writer.WriteAttribute("readonly", "readonly");
if (!String.IsNullOrEmpty(inputClassName))
{
writer.WriteAttribute("class", inputClassName);
}
writer.WriteAttribute("value", value);
writer.Write(HtmlTextWriter.SelfClosingTagEnd);

_disableAutoAccessKey = oldDisableAutoAccessKey;
}

// Can't be static because it uses MakeChildId
public void WriteCheckBox(HtmlTextWriter writer, string
labelClassName, string labelText, string inputClassName, string id, bool
isChecked)
{
writer.WriteLine();
writer.WriteBeginTag("input");
writer.WriteAttribute("type", "checkbox");
if (!String.IsNullOrEmpty(inputClassName))
{
writer.WriteAttribute("class", inputClassName);
}
writer.WriteAttribute("id", MakeChildId(id));
writer.WriteAttribute("name", MakeChildName(id));
if (isChecked)
{
writer.WriteAttribute("checked", "checked");
}
if (AutoAccessKey && (!String.IsNullOrEmpty(labelText)))
{
writer.WriteAttribute("accesskey", labelText[0].ToString());
}
writer.Write(HtmlTextWriter.SelfClosingTagEnd);

WriteLabel(writer, labelClassName, labelText, id);
}

// Can't be static because it uses MakeChildId
public void WriteSubmit(HtmlTextWriter writer, ButtonType buttonType,
string className, string id, string imageUrl, string javascript, string
text)
{
writer.WriteLine();

string idWithType = id;

switch (buttonType)
{
case ButtonType.Button:
writer.WriteBeginTag("input");
writer.WriteAttribute("type", "submit");
writer.WriteAttribute("value", text);
idWithType += "Button";
break;
case ButtonType.Image:
writer.WriteBeginTag("input");
writer.WriteAttribute("type", "image");
writer.WriteAttribute("src", imageUrl);
idWithType += "ImageButton";
break;
case ButtonType.Link:
writer.WriteBeginTag("a");
idWithType += "LinkButton";
break;
}

if (!String.IsNullOrEmpty(className))
{
writer.WriteAttribute("class", className);
}
writer.WriteAttribute("id", MakeChildId(idWithType));
writer.WriteAttribute("name", MakeChildName(idWithType));

if (!String.IsNullOrEmpty(javascript))
{
string pureJS = javascript;
if (pureJS.StartsWith("javascript:"))
{
pureJS = pureJS.Substring("javascript:".Length);
}
switch (buttonType)
{
case ButtonType.Button:
writer.WriteAttribute("onclick", pureJS);
break;
case ButtonType.Image:
writer.WriteAttribute("onclick", pureJS);
break;
case ButtonType.Link:
writer.WriteAttribute("href", javascript);
break;
}
}

if (buttonType == ButtonType.Link)
{
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(text);
writer.WriteEndTag("a");
}
else
{
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}
}

static public void WriteRequiredFieldValidator(HtmlTextWriter writer,
RequiredFieldValidator rfv, string className, string controlToValidate,
string msg)
{
if (rfv != null)
{
rfv.CssClass = className;
rfv.ControlToValidate = controlToValidate;
rfv.ErrorMessage = msg;
rfv.RenderControl(writer);
}
}

static public void WriteRegularExpressionValidator(HtmlTextWriter
writer, RegularExpressionValidator rev, string className, string
controlToValidate, string msg, string expression)
{
if (rev != null)
{
rev.CssClass = className;
rev.ControlToValidate = controlToValidate;
rev.ErrorMessage = msg;
rev.ValidationExpression = expression;
rev.RenderControl(writer);
}
}

static public void WriteCompareValidator(HtmlTextWriter writer,
CompareValidator cv, string className, string controlToValidate, string
msg, string controlToCompare)
{
if (cv != null)
{
cv.CssClass = className;
cv.ControlToValidate = controlToValidate;
cv.ErrorMessage = msg;
cv.ControlToCompare = controlToCompare;
cv.RenderControl(writer);
}
}

static public void WriteTargetAttribute(HtmlTextWriter writer, string
targetValue)
{
if ((writer != null) && (!String.IsNullOrEmpty(targetValue)))
{
// If the targetValue is _blank then we have an opportunity
to use attributes other than "target"
// which allows us to be compliant at the XHTML 1.1 Strict
level. Specifically, we can use a combination
// of "onclick" and "onkeypress" to achieve what we want to
achieve when we used to render
// target='blank'.
//
// If the targetValue is other than _blank then we fall back
to using the "target" attribute.
// This is a heuristic that can be refined over time.
if (targetValue.Equals("_blank",
StringComparison.OrdinalIgnoreCase))
{
string js = "window.open(this.href, '_blank', ''); return
false;";
writer.WriteAttribute("onclick", js);
writer.WriteAttribute("onkeypress", js);
}
else
{
writer.WriteAttribute("target", targetValue);
}
}
}
}

public class ControlRestorationInfo
{
private Control _ctrl = null;
public Control Control
{
get { return _ctrl; }
}

private ControlCollection _coll = null;
public ControlCollection Collection
{
get { return _coll; }
}

public bool IsValid
{
get { return (Control != null) && (Collection != null); }
}

public ControlRestorationInfo(Control ctrl, ControlCollection coll)
{
_ctrl = ctrl;
_coll = coll;
}

public void Restore()
{
if (IsValid)
{
_coll.Add(_ctrl);
}
}
}
hope you like it
tim

"John" <Jo************@AOL.netwrote in message
news:em*************@TK2MSFTNGP05.phx.gbl...
>>Hi there,

I was reading an article
(http://avenuea-razorfish.com/article...ion_Turbek.pdf)
on 'all-menu navigation' and I'd like to try and implement this in my
site. Can anyone recommend how to get started?

Is there an Ajax control available for this or would more a basic
javascript work just as well. I'm assuming I just need a div element
that is shown on a mouse over, but I'm not sure how to go about aligning
all of the sub menu items etc?

Please help a newbie!

Best regards

John

Jan 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: MP Multimedia | last post by:
Hello everyone, I need help. I'm using a hierarchical menu made in javascript. When I used it in a one frame page, it came out fine. But now I need to change my page to 3 frames: a top frame,...
22
by: Marek Mand | last post by:
How to create a functional *flexible* UL-menu list <div> <ul> <li><a href=""></li> <li><a href=""></li> <li><a href=""></li> </ul> </div> (working in IE, Mozilla1.6, Opera7 (or maybe even...
10
by: Gernot Frisch | last post by:
Hi, I have found some menu functions. It works quite well, but how can I replace it with a simple <a href> if javascript is turned off? I reduced my code to:...
2
by: Brian | last post by:
Hello, I want to design some menus for websites with submenus. I'd like to learn the code myself and I was wondering a good place to pick up on some tips on how to design them. Also, is there...
2
by: Sisnaz | last post by:
I'm working with 2005 Beta 2 and I'm sure this is a trivial question but for the life of me I can't figure out. I placed a menu navigation componet on my master page and defined the navigation...
0
by: Garmt de Vries-Uiterweerd | last post by:
X-posted to opera.page-authoring, because this is a bit Opera-specific for the moment. F'up to ciwas. I am playing around with dedicated styling for the projection media type.. Currently the...
1
by: Paul | last post by:
Below is the html and css. It works in Firefox but not IE. When you click on "Your Links", it should cause a new menu "system" to open up to the right of the "Your Links" with two menu options. ...
4
by: tburger | last post by:
Hey everyone- This is my first post at The Scripts, but I've used the forums before for other programming issues. Hopefully, someone has some solid styling advice for me. I've now been dealing...
1
by: Fabx | last post by:
Hallo, sorry for my english. I want to build a navigation menu with the repeat control, the items of menu are in a table of database. All items of the menu have class="MenuLink", but the...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.