Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi..

As you know by default asp.net menu control opens sub items on mouse over event.

I want to change on mouse over to onclick event. so when use click on parent item, it should open subitem and on next click it should close the menu.

Please give me some tips,tricks to do the same.

Regards,
Posted

 
Share this answer
 
Comments
Vijay Radia 30-May-12 1:47am    
thanks for your respose but i already tried that javascript, but its not working once the page gets posted back.
I only need to use menu control and cant use treeview or other.
Ok i got it now.

Do following :

Create one class derived from menu control.

Override render event

C#
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

            Dim stringBuilder As StringBuilder = New StringBuilder()
            Dim stringWriter As StringWriter = New StringWriter(stringBuilder)

            Dim htmlWriter As HtmlTextWriter = New HtmlTextWriter(stringWriter)
            MyBase.Render(htmlWriter)

            Dim html As String = stringBuilder.ToString()

            Dim strMouseHover = "onmouseover=""Menu_HoverStatic(this)"""
            Dim strMouseClick = "onclick=""Menu_HoverStatic(this)"""

            Dim str As Boolean = html.Contains(strMouseHover)


            html = html.Replace(strMouseHover, strMouseClick)

            writer.Write(html)

        End Sub

Then overide Menu_HoverStatis(this) function as per below link:
http://forums.asp.net/t/1156758.aspx
 
Share this answer
 
v2
Comments
anamikas 1-Oct-13 1:26am    
I have overridden the render method in a custom control, but sub menu is still not displaying when the parent menu is clicked. Pls help.
I have overridden the render method in a custom control, but sub menu is still not displaying when the parent menu is clicked. Pls help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900