Asp.NET菜单,点击而不是onhover打开和关闭子项 [英] Asp.NET Menu, open and close subitem on click instead of onhover

查看:94
本文介绍了Asp.NET菜单,点击而不是onhover打开和关闭子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..



正如您所知,asp.net菜单控件在鼠标悬停事件时打开子项。



我想将鼠标改为onclick事件。所以当使用时点击父项,它应该打开子项,然后在下一次点击它应该关闭菜单。



请给我一些提示,做同样的技巧。



问候,

解决方案

见以下链接



http://forums.asp.net/t/1250342.aspx [ ^ ]


好的,我知道了现在。



如下:



创建一个从菜单控件派生的类。



覆盖渲染事件



受保护的覆盖子渲染(ByVal writer As HtmlTextWriter)

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

Dim htmlWriter As HtmlTextWriter = New HtmlTe xtWriter(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



然后将Menu_HoverStatis(this)功能置于以下链接:

http://forums.asp.net/t/1156758.aspx


我已在自定义控件中重写了render方法,但单击父菜单时仍未显示子菜单。请帮忙。


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,

解决方案

see below link

http://forums.asp.net/t/1250342.aspx[^]


Ok i got it now.

Do following :

Create one class derived from menu control.

Override render event

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


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.


这篇关于Asp.NET菜单,点击而不是onhover打开和关闭子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆