查找UnorderedList< UL>母版页内的控件在asp.net内容页 [英] Find a UnorderedList <UL> control inside a master page from a content page in asp.net

查看:134
本文介绍了查找UnorderedList< UL>母版页内的控件在asp.net内容页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到一个UL控制,然后发现,UL中的LI和来自内容网页指定一个CSS类的....

I want to find a UL control and then find a LI within that UL and assign a css class to that from a content page....

<ul id="mainMenu" runat="server" style="width:350px;">
            <li id="mainHome" runat="server"><a title="Home" href="#" class="home">Home</a></li>
            <li id="mainManage" runat="server"><a title="Manage" href="#" class="manage">Manage</a></li>
            <li id="mainEnquiry" runat="server"><a title="Enquiry" href="#" class="enquiry">Enquiry</a></li>
            <li id="mainReport" runat="server"><a title="Report" href="#" class="report">Reports</a></li>

            </ul>

如果用户点击首页这被重定向到users.aspx页,我想强调李家用一种颜色...... PLZ给我的建议...

If the user clicks home it is redirected to users.aspx page and i want to highlight Home LI with a color... Plz give me suggestion...

推荐答案

如果我理解这一点正确...

If I have understood this correctly...

如果您的列表是母版页上...

If your list is on the master page...

<ul runat="server" id="list">
    <li runat="server" id="home">Home</li>
    <li runat="server" id="news">News</li>
</ul>

...那么您可以将您的内容网页上做到这一点...

...then you can do this on your content page...

Control list = this.Page.Master.FindControl("list");

然后,李对象将在列表对象控制 - 例如 list.Controls 。或者,你可以做...

Then the li objects will be controls in the list object - e.g. list.Controls. Or you can do...

Control home = this.Page.Master.FindControl("list").FindControl("home");

...找到列表控件的具体控制。

...to find specific controls of the list control.

在使用上的HTML =服务器控制服务器端等价的对象将 HtmlGenericControl

When using the runat="server" on the HTML controls the server side equivalent object will be HtmlGenericControl.

如果你想一类适用于 LI 标签,你会做什么是投在 LI 对象到 HtmlGenericControl 并然后使用属性属性。例如...

If you want to apply a class to the LI tags what you would have to do is cast the LI object to a HtmlGenericControl and then use the Attributes property. For example...

HtmlGenericControl home = (HtmlGenericControl)this.Page.Master.FindControl("list").FindControl("home");

home.Attributes["class"] = "className";

希望帮助...

Hope that helps...

这篇关于查找UnorderedList&LT; UL&GT;母版页内的控件在asp.net内容页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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