.NET Menu Control - "onclick" doesn't work... alternatives, solutions, questions?

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.

11/6/2008 3:50:22 PM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 10

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

11/6/2008 4:27:29 PM

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 Menu

Inherits 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)


Dim html As String = stringBuilder.ToString

html = 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

This 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.

11/6/2008 4:36:08 PM


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");


        [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
        protected override void RenderContents(HtmlTextWriter writer)
            writer.Write("Custom Contents");

 If you want to know more ,please refer to the article .


wish can help you  

11/11/2008 5:13:42 AM


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?

11/11/2008 3:14:01 PM

Similar Artilces:

User Control Question: Button Onclick Event won't work (won't fire)
Hi all, I create a webusercontrol and load it to home page dynamicly using Place Holder . However, the Button Onclick Event won't work (won't fire) in my Web user Control. Here are the codes. Partial Class test2 Inherits System.Web.UI.UserControl Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click End Sub End Class  ************************************ I set break point to (Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click). Can anyone tell me whats going wrong with my code? Thanks a lot! ...

Selected menu item of menu control doesn't work well for URL with querystring
I have a site map with url with querystrings. For example,page1.aspx?m=xxxAnd the selected menu won't work with these kind of URL? Any workaround?  Hi, nkw:And the selected menu won't work with these kind of URL? Could you please post more detail about how the selected menu does not work with the URL with querystring?Amanda WangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help. more info needed!Click “Mark as Answer” on the post when it helped....

Can't get the Web Controls to work.. The Build.Bat file doesn't work? HELP>> ARGGG>.
Hi.. I was wanting to use the IE Web Controls, the Tab Strip, etc, and play with it.. Since I have IIS 5, I thought I'd copy them there using the Read me.txt instructions and then copy to a dev server that I use at a web host.. Well, everything worked except the Build file doesn't build the Microsoft.UI.Webcontrols.DLL file? When I try to run it by double clicking on it, it runs really fast in  the DOS window, but I can't see what it says and it closes.. So I tried to do so manually and I received an error that the "cse.exe is not recognized as an internal or external command or batch...

Freenx doesn't work, NX doesn't work with compiz. Questions
FreeNX just doesn't work. NX from nomachine installed well, but I guess that limits me to two logins? NX doesn't work with compiz, tho, at least from machines not running compiz. So no great surprise. :-) Is there any way to run startkde that disables compiz and uses kwin? Alternatively, hows the easiest way to handle alternative logins? I could link the two documents folders together, but then I'd have problems with file permissions. I'm just looking for ideas here, I could live with two logins. -- dougnc -------------------------------------------...

'Tab' control 's visible doesn't work.Why?
I use tab control in my applition. And I set visible=false, but it doesn't work. my code is: ----------------------------------------------- <asp:ScriptManager ID="ScriptManager1" runat="server" />  <div>   <ajaxToolkit:TabContainer runat="server" ID="Tabs" Height="138px" ActiveTabIndex="0"    Width="402px">    <ajaxToolkit:TabPanel runat="server" ID="Panel1" HeaderText="Tab1" Visible="f...

Insert() method of datasource control doesn't work with wizard control
Hello, I have wizard control with textboxes and checkboxes in it. the wizard control has two steps with each step having text data to be stored in the sql database. I used the sqldatasource control and set it up to do the insert... and when I tested it, I got an error stating it couldn't find the control parameter for the first field. I am guessing this is because the fields are in step 1 of the wizard control, and the finish button is in step 2. How can I get all of the contols in the Wizard control to be seen by the datasource control?   Thanks in advanceJust trying to ...

.NET Remoting
Hi,I'm trying to write Remote server object , when I write:using System.Runtime.Remoting.Channel.TcpIt looks like this namespace doesn't exist and I can't use instances of objects in this name space as I used in .NET 1.1When I look at the documentation, it looks like there is no change in the syntex or methodology.Can some one please help me.all the best,el System.Runtime.Remoting.Channels.Tcp...

Password strength control doesn't work in a modal popup control??
I didn't just post this..I searched first...nothing found.  Can someone confirm that the password strength control doesn't work in a modal popup control??    Works Ok on a page. The tag/prefix is- "AjaxControlToolkit" Here is the markup:         <asp:Panel ID="Panel1" runat="server" BackColor="#C0FFFF" BorderColor="DarkGreen" BorderStyle="Solid"            BorderWidth="2px" ForeColor="#C04000" Height="176px" Style="left: 288px; position: relative;   &...

Navigation Menu control don't work
Okay, so I thought to use the Navigation Menu control is as simple as drag and drop then specify the Web.sitemap file and that is it. Well, it didn't work. Nothing shows up in the page. In VS08, the menu does show up in design mode but when viewing the browser, nothing shows up. Any suggestion? Hi, mychucky:Okay, so I thought to use the Navigation Menu control is as simple as drag and drop then specify the Web.sitemap file and that is it. Do you draged a SiteMapDataSource Control from the toolbox, and dropped it on the page, and then set the Menu's DataSourceID's ...

StaticItemTemplate of Menu control doesn't work!
Here is my code. It shows me the text of the menu items in the designer view, but when I open it in the IE, there is no text.There isn't also any single example in Internet or in the book of Alex Homer.<asp:Menu Width=700px ID="Menu1" Orientation="Horizontal" runat="server" OnMenuItemClick="Menu1_MenuItemClick" > <Items> <asp:MenuItem Text="step1" Value="step1" Selected="True"></asp:MenuItem> <asp:MenuItem Text="step2" Value="step2"></asp:MenuItem> </Items> <StaticItemTemplate> <table border=1 width=100% > <tr> <td...

Initialize the control on Page_Load, Add the control On event. IT DOESN'T WORK
Hi. I have created a DropDownList and a CustomValidator for that list. When I did it all on event, it all worked fine. However, the CustomValidator didn't give the desired results due to the simple fact that the Ddl was reinitialized on the event, so the CustomValidator treated it as untouched, again. (Stupid.) So, I decided to Initialize both controls on Page_Load and Add them on event. However, when i try to form1.Add em, i get a "Value cannot be null." for the control that I *DID* build and initialize on Page_Load. What's wrong??? Here's the Page_Load: public void Pa...

Menu Control style doesn't work in Internet Explorer
Hello @all, i have a web project with the asp.net 2.0 menu control. In Visual Studio 2005 Pro the style of the menu is displayed good. But when i open the Website in Internet Explorer the Sytle isn't displayed. Only the menu Buttons are there without a style. Can anybody help me ? Thanks BN   I have exactly the same problem. I have set up a Menu Control in a MasterPage and set the AutoFormat to Classic and get the following code: <asp:Menu ID="Menu1" runat="server" BackColor="#B5C7DE" DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98"...

Don't waste your time: IE Web Controls doesn't work for 1.1
From MSDN: "This product is only compatible with machines running builds of the .NET Framework (1.0.3705.0) and Visual Studio® .NET (7.0.9466)." http://msdn.microsoft.com/downloads/samples/internet/ASP_DOT_NET_ServerControls/WebControls/default.asp Works just fine for me. And Microsoft uses it with Content Management Server 2002 on Windows 2003...... I've had no problems with the IE Web Controls on 1.1 whatsoever. As a matter of fact, I have them running on a 8-node web farm. VladTheImpaler, MSDN contains outdated data (readme January 22, 2003). If that was...

DynamicMenuItemStyle doesn't work well together with DynamicHoverStyle in menu control
If the background-color is set for the dynamicmenuitem, then it will overwrite whatever you set for the background-color of the dynamichoverstyle. Any workaround?thanks...

Repeater Containing Custom Control Doesn't Work With Page ViewState On Unless I Don't ReBind...
I have create a custom composite drop down list control that does not save view state for all properties.  There is a requirement that this contol work in a Repeater.  I have tested the contol in a repeater in various ways.  This is my first post ever, so I apologive if I have provided too little, too much or the wron info. Note: The Repeater was always created in the aspx file.  1) Page.EnableViewState = true , and my control added to the repeater programmatically via the ItemDataBound event. 2) Page.EnableViewState = false, and my control added to the repea...

Web resources about - .NET Menu Control - "onclick" doesn't work... alternatives, solutions, questions? - asp.net.navigation-controls

Resources last updated: 12/12/2015 5:43:30 AM