Unfortunately for the .NET developers who have struggled with this problem for quite some time, there hasn't been a solution unless I'm missing something. The ASP.net Menu Control simply cannot support the "onclick" command instead of the "onmouseover" command. I have had some success with the method that Roshadar has posted in the past, but unfortunately, the Menu_HoverDynamic functionality still reverts to only the Hover state and not when clicked.
My questions are these:
Has anyone found a way to allow "onclick" capabilities on the Menu?
If not, what is the best alternative menu out there that I can easily use as a horizontal menu with OnClick? Can it use SiteMaps?
Does Microsoft intend on adding the OnClick functionality to the Menu Control, or am I damned to using or creating my own controls?
I ask this simply to know if there is an easier solution than the solutions I have been programming in the past. Stringing together recursive functions and creating divs, css, and using javascript isn't too hard these days after putting it all together in the past, but I'd love a .NET out-of-the-box solution to this if it's on its way.
![]() |
0 |
![]() |
Are you looking for the OnMenuItemClick? or something else? Because i use the OnMenuItemClick all the time to catch client side actions and pass parameters from the menu choices..
And since this is standard built-in asp.net it does work with sitemaps- i have even created a class to run SQL instead of the xml.
Please clarify- Thank you Jeremy
![]() |
0 |
![]() |
I understand that the Menu control works with a SiteMap. I'm asking if there are alternatives that do as well.
To clarify, here's exactly what needs to be done in order to override the HOVER styling and functionality of the Menu. As per a suggestion on this forum, a custom Menu control needs to be created and attributes need to be replaced during the Render.
Namespace MyControls Public Class MenuInherits System.Web.UI.WebControls.Menu Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)Dim stringBuilder As StringBuilder = New StringBuilder Dim stringWriter As IO.StringWriter = New IO.StringWriter(stringBuilder)Dim htmlWriter As HtmlTextWriter = New HtmlTextWriter(stringWriter) MyBase.Render(htmlWriter) Dim html As String = stringBuilder.ToStringhtml = html.Replace("onmouseover=""Menu_HoverDynamic(this)""", "onmouseover=""this.style.background='gray';"" onclick=""Menu_HoverDynamc(this)""")
html = html.Replace("onmouseout=""Menu_Unhover(this)""", "onmouseout=""this.style.background='#1052A0';""") writer.Write(html)
End Sub
End Class
End NamespaceThis is an example of some of the tinkering I've been doing. While theoretically, that should work. The Menu_HoverDynamic function is still setup to function when a Hover occurs. It's also working with the LINK that is on the MenuItem. When I CLICK, poof... the Menu dropdown disappears instead of Expanding out the next set of menuitems. Doesn't seem to be able to be replaced.
![]() |
0 |
![]() |
Hi,
Based on my understanding,you would like to change the attribute of menu controls ?
if yes, you can try to inherit the "System.Web.UI.WebControls.Menu" and override the "AddAttributesToRender" and "RenderContents" functions .Such as :
public class cusmenu:System.Web.UI.WebControls.Menu { public cusmenu() { } [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] protected override void AddAttributesToRender(HtmlTextWriter writer) { writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');"); writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red"); base.AddAttributesToRender(writer); } [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] protected override void RenderContents(HtmlTextWriter writer) { writer.Write("Custom Contents"); base.RenderContents(writer); } }If you want to know more ,please refer to the article .
http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.webcontrol.addattributestorender(VS.80).aspx
wish can help you
![]() |
0 |
![]() |
Interesting...
My problem is that I want to use the Hover "functionality" as an OnClick. I would like the menu to popout on a click, not on a Hover. I can't simple change the onmouseover to onclick because from what it looks like, Hover_Dynamic still has javascript within it that only goes with the :hover commands.
Could this potentially solve my problem?
![]() |
0 |
![]() |