如何在内容页面加载事件中删除主页的特定href [英] How do I remove a specific href of masterpage at content page load event
问题描述
这是在Master Page:
< div class =appListid =appListMainrunat =server>
< a href =javascript:void(0)class =closebtnonclick =closeNav()>& times;< / a>
< a href =#>关于< / a>
< a href =#>服务< / a>
< a href =# >客户< / a>
< a href =#>联系< / a>
< / div>
< / div>
对我来说,closebtn是importatn,我想保留。
其余的我想删除,因为我可以稍后添加。
我尝试过的事情:
protected void Page_Load(object sender,EventArgs e)
{
控制c = this.Master.FindControl(appListMain );
c.Controls.Clear(); //不幸的是我失去了closebtn,我需要关闭这个滑动条。
//这样添加新的Control。
HyperLink hl1 =新的HyperLink();
hl1.Text =点击这里;
hl1.NavigateUrl =UserValidation.aspx;
c.Controls.Add(hl1);
在创建链接时,是否可以将类添加到要删除的链接中?
< a class =hideItemhref =#>关于< / a>
< a class =hideItemhref =#>服务< / a>
< a class =hideItemhref =#>客户< / a>
< a class =hideItemhref =#>联系< / a>
编辑:您似乎想要删除服务器上的项目这看起来类似的解决方案查找无序列表< UL>从asp.net中的内容页面控制母版页内的内容 - Stack Overflow [ ^ ]
客户端删除项目:
.remove()| jQuery API文档 [ ^ ]
// 使用jQuery隐藏项目(可以使用JavaScript查找类似的功能)
< script type = text / javascript>
( window )。load( function (){
(' 。hideItem')。remove(); // 在链接中描述
});
< / script>
This is at Master Page:
<div class="appList" id = "appListMain" runat ="server">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
</div>
For me "closebtn" is importatn, I want to keep.
Rest of them I want to remove, as I can add later myself.
What I have tried:
protected void Page_Load(object sender, EventArgs e)
{
Control c = this.Master.FindControl("appListMain");
c.Controls.Clear(); //Unfortunately I lose "closebtn" that I need to close this slidebar.
//Thus adding new Control.
HyperLink hl1 = new HyperLink();
hl1.Text = "Click Here";
hl1.NavigateUrl = "UserValidation.aspx";
c.Controls.Add(hl1);
On creating the links, can you add class to the links to be removed?
<a class="hideItem" href="#">About</a> <a class="hideItem" href="#">Services</a> <a class="hideItem" href="#">Clients</a> <a class="hideItem" href="#">Contact</a>
Edit: you seem to want to remove items at server side, this looks similar solution Find a UnorderedList <UL> control inside a master page from a content page in asp.net - Stack Overflow[^]
Client side removing of items:
.remove() | jQuery API Documentation[^]
//hide the items using jQuery (can find similar functionality with JavaScript) <script type="text/javascript">
(window).load(function() {
('.hideItem').remove(); //described in link }); </script>
这篇关于如何在内容页面加载事件中删除主页的特定href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!