如何为页面上的 2 个实例的用户控件内的元素设置 html id
我是 ASP.NET 领域的新手,我已经搜索并阅读过,但没有运气。
我有一个标准的无序嵌套列表,用于网站的主要水平导航,我还在网站左栏中使用相同的嵌套列表作为垂直导航,并将其动画化为树形导航。
为了简单的维护,我希望有一个包含嵌套导航列表的用户控件,并将其添加到页面两次。
该网站正在使用母版页。在母版页中,我可以在标题和侧栏中调用用户控件两次,但我需要能够为导航 UL 的每个实例单独设置 html id,以便我可以使用 js 来定位它们。
我只能使用内联 asp.net,因为我目前无法访问后面的代码。
我希望能够在母版页中包含一个属性,例如 clientID 例如:
<uc3:mainnav id="mainnav" clientID="main-nav" runat="server"></uc3:mainnav>
<uc3:mainnav id="sidebarnav" clientID="sidebar-nav" runat="server"></uc3:mainnav>
或者是否可以在母版页中的这些行中放置一些其他属性/值,然后用户控件可以读取这些属性/值并设置控件中最高 ul 元素的 id。
正如前面提到的,我受到外部各方的限制,只能使用 ASP.NET 2.0 内联执行此操作,并且无法使用隐藏代码执行此操作。
I'm new to the land of asp.net, I've searched and read up but have had no luck with this.
I have a standard unordered nested list which I'm using for the main horizontal navigation of my site, I am also using the same nested list as a vertical navigation in the left column of the website, which I animate as a tree style nav.
For simple maintenance I'd like to have one user control containing the nested nav list and add that twice to the page.
The site is using masterpages. In a master page I can call the user control twice to occur in the header and in the sidebar, but I need to be able to set the html id individually for each one of these instances of the nav UL so I can target them with js.
I am constrained to using in-line asp.net as I currently no access to code behind.
I was hoping to be able to include an attribute like maybe clientID in the masterpage
e.g. :
<uc3:mainnav id="mainnav" clientID="main-nav" runat="server"></uc3:mainnav>
<uc3:mainnav id="sidebarnav" clientID="sidebar-nav" runat="server"></uc3:mainnav>
or alternatively is it possible to put some other attribute/value in these lines in a masterpage which could then be read by the user control and set the id of highest ul element in the control.
As previously mentioned I'm constrained by external parties to doing this with asp.net 2.0 inline and can't do this with code behind.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以向 UserControl 添加一个属性来指定您想要的任何内容。然后可以在控件声明的标记中指定该属性名称和值,就像任何其他控件一样。
You can add a property to the UserControl that specifies anything you want. This property name and value can then be specified in the markup for the declaration of the control just as with any other control.