母版页中的菜单。 [英] Menu in master page.

查看:78
本文介绍了母版页中的菜单。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在点击它时显示活动的菜单项但是菜单在我的母版页上,为什么我无法完成此任务。任何人都可以指导我吗?





 < span class =code-keyword><   div     class   =  menu_nav >  
< ul >
< li > < a href = < span class =code-keyword> Home.aspx class = 有效 > 主页< / a > < / li >
< li > < a href = Services.aspx class = 无效 > 服务< / a > < / li >
< < span class =code-leadattribute> li > < a href = Aboutus.aspx class = 无效 > 关于我们< / a > < / li > ;
< li > < a href = Login.aspx class = 无效 > 登录< / a > < / li >
< li > < a href = Contactus.aspx class = 无效 > 联系我们< / a > < / li >
< / ul >



我在这样的母版页中的代码,当我点击它时,我想显示活动的菜单项,例如当我点击它的高亮显示主页时很快将会是什么我这样做?





从回答[/编辑]

解决方案

你应该为设置值StaticSelectedStyle-CssClass 属性。它看起来像是:



 <   asp:菜单    ID   =  Menu1    runat   =  server    StaticSelectedStyle-CssClass   =  yourcssclass >  
< 项目 >
< asp:MenuItem 文字 = 主页 > < / asp:MenuItem >
< asp:MenuItem < span class =code-attribute>文本 = 关于 > < / asp:MenuItem >
< / Items >
< / asp:Menu >





如果是m请投票你的回答对你很有帮助。


你可以在你的内容页面做以下事情: -

只需从Master Page找到控件,



HtmlAnchor示例=(HtmlAnchor)Master.FindControl(示例);

example.class =selected;



对于HtmlAnchor,你必须添加System.Web.UI.HtmlControls命名空间。



但它会在Example.Class中给出错误bcz它不会获得类属性。



这里是锚点(a)标签的w3规范:







1.<!ELEMENT A - - (%inline;)* - (A) - 锚 - >

2.<!ATTLIST A

3.%attrs; - %coreattrs,%i18n,%事件 -

4. charset%Charset; #IMPLIED - 链接资源的字符编码 -

5.输入%ContentType; #IMPLIED - 咨询内容类型 -

6.名称CDATA #IMPLIED - 命名链接结束 -

7. href%URI; #IMPLIED - 链接资源的URI -

8. hreflang%LanguageCode; #IMPLIED - 语言代码 -

9. rel%LinkTypes; #IMPLIED - 转发链接类型 -

10. rev%LinkTypes; #IMPLIED - 反向链接类型 -

11. accesskey%字符; #IMPLIED - 辅助功能键字符 -

12. shape%Shape; rect - 用于客户端图像映射 -

13. coords%Coords; #IMPLIED - 用于客户端图像映射 -

14. tabindex NUMBER #IMPLIED - 按Tab键顺序排列 -

15. onfocus%Script; #IMPLIED - 元素得到了关注 -

16. onblur%Script; #IMPLIED - 元素失去焦点 -

17.>



如你所见,没有课程属于那里,所以这只是我的一个傻瓜。



令人讨厌的是,似乎没有简单的方法可以做我正在尝试做的事情使用HTML锚点,

所以我将不得不使用其他一些元素(例如ASP.NET Button,或某些东西或服务器Control< asp:HyperLink>)。没什么大不了的。





====================== =======================================

如果您使用< asp:hyperlink xmlns:asp =#unknown>那么事情对你来说很容易,



Master.master页面: -



< asp: hyperlink id =tab_homerunat =servernavigateurl =ABC.aspx>

< asp:hyperlink id =tab_loginrunat =servernavigateurl =>



在内容页面上:(这里是ABC.aspx)



从这样的母版页中找到Ur Control



HyperLink hlCart =(HyperLink)Master.FindControl(tab_cart);

hlCart.CssClass =selected;



在这里你可以指定CSSCLASS =SELECTED。



我希望这能帮到你。

全部最佳


在您的母版页中添加以下代码....



 私有 mSelMenuItem  as   string  = 没有 

公共 属性 SelMenuItem as string
get
return mSelMenuItem
end get
set (value as string
mSelMenuitem = value
end set
end property

公共 功能 GetMyMenuState( ForThisMenuItem as string as string
如果 ForThisMenuItem = mSelMenuItem 那么
返回 class =& chr( 34 )& active& chr( 34 )&
其他
返回 class =& chr( 34 )& 不活动& chr( 34 )&
结束 如果
结束 功能







然后......在表单加载事件的每个内容页面中添加一个SINGLE语句以标识母版页面的页面...

这样的主页...

  me  .master.SelMenuItem =  主页 





或类似服务页面



  me  .master.SelMenuItem =  服务 







然后在你的主页上,菜单是....

你可以像这样使用它...



< li>< a href =homepage.aspx<%= GetMyMenuState(Home)%>>主页< / a>< / li> 
< li>< a href =services.aspx<%= GetMyMenuState(服务)%>>服务< / a>< / li>


i want to show active my menu item when i am click on it but the menu is on my masterpage that why i am not able to do this task. can any one guide me??

[EDIT]

<div class="menu_nav">
        <ul>
          <li ><a href="Home.aspx" class="active">Home</a></li>
          <li ><a href="Services.aspx" class="inactive">Services</a></li>
          <li><a href="Aboutus.aspx" class="inactive">About Us</a></li>
          <li><a href="Login.aspx" class="inactive">Login</a></li>
          <li><a href="Contactus.aspx" class="inactive">Contact Us</a></li>
        </ul>


my code in masterpage like this and I want to show active menu item when i am click on it for example when I click on home its highlight home and soon what will I do for it??


moved from answer[/EDIT]

解决方案

You should set value for StaticSelectedStyle-CssClass attribute. It will look like:

<asp:Menu ID="Menu1" runat="server" StaticSelectedStyle-CssClass="yourcssclass">
            <Items>
                <asp:MenuItem Text="Home"></asp:MenuItem>
                <asp:MenuItem Text="About"></asp:MenuItem>
            </Items>
        </asp:Menu>



Please vote if my answer will help you.


You can do following thing in your Content page :-
Just find control from Master Page ,

HtmlAnchor example = (HtmlAnchor)Master.FindControl("example");
example.class = "selected";

For HtmlAnchor you have to add "System.Web.UI.HtmlControls" namespace.

But it will gives u error in " Example.Class " bcz it won''t get class attributes.

See here is the w3 specification for the anchor (a) tag:



1. <!ELEMENT A - - (%inline;)* -(A) -- anchor -->
2. <!ATTLIST A
3. %attrs; -- %coreattrs, %i18n, %events --
4. charset %Charset; #IMPLIED -- char encoding of linked resource --
5. type %ContentType; #IMPLIED -- advisory content type --
6. name CDATA #IMPLIED -- named link end --
7. href %URI; #IMPLIED -- URI for linked resource --
8. hreflang %LanguageCode; #IMPLIED -- language code --
9. rel %LinkTypes; #IMPLIED -- forward link types --
10. rev %LinkTypes; #IMPLIED -- reverse link types --
11. accesskey %Character; #IMPLIED -- accessibility key character --
12. shape %Shape; rect -- for use with client-side image maps --
13. coords %Coords; #IMPLIED -- for use with client-side image maps --
14. tabindex NUMBER #IMPLIED -- position in tabbing order --
15. onfocus %Script; #IMPLIED -- the element got the focus --
16. onblur %Script; #IMPLIED -- the element lost the focus --
17. >

As you can see, there''s no class attribute there, so this is just me being a moog.

Annoyingly, it looks like there''s no easy way to do what I''m trying to do using the HTML anchor,
so I''ll have to use some other element (such as an ASP.NET Button, or something or server Control <asp:HyperLink>). No big deal.


=============================================================
If You use <asp:hyperlink xmlns:asp="#unknown"> then thing will be easy for you,

Master.master Page :-

<asp:hyperlink id="tab_home" runat="server" navigateurl="ABC.aspx">
<asp:hyperlink id="tab_login" runat="server" navigateurl="">

On Content Page : (Here ABC.aspx)

Just Find Ur Control from master page like this

HyperLink hlCart = (HyperLink)Master.FindControl("tab_cart");
hlCart.CssClass = "selected";

Here you can assign CSSCLASS="SELECTED".

I Hope this will Help you.
All d best


In your master page add the following code....

Private mSelMenuItem as string = nothing

Public property SelMenuItem as string
  get
    return mSelMenuItem
  end get
  set (value as string)
    mSelMenuitem = value
  end set
end property

Public Function GetMyMenuState(ForThisMenuItem as string) as string
  If ForThisMenuItem = mSelMenuItem Then
    Return ("class=" & chr(34) & "active" & chr(34) & " ")
  Else
    Return ("class=" & chr(34) & "inactive" & chr(34) & " ")
  End If
End Function




then... in EACH of your CONTENT Pages in the form load event add a SINGLE statement to identify the page to the master page...
like this for the homepage...

me.master.SelMenuItem = "Home"



or like this for services page

me.master.SelMenuItem = "Services"




Then in your masterpage where the menu is....
you can use it like this ...

<li><a href="homepage.aspx" <%=GetMyMenuState("Home") %>>Home</a></li>
<li><a href="services.aspx" <%=GetMyMenuState("Services") %>>Services</a></li>


这篇关于母版页中的菜单。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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