我的母版页中有一个超链接,我没有该链接的ID ..我需要从当前的aspx页中隐藏超链接.如何执行此操作? [英] I have an hyperLink in master page i don't have id for that link ..I need to hide hyperlink from my current aspx page.How can I do this?

查看:94
本文介绍了我的母版页中有一个超链接,我没有该链接的ID ..我需要从当前的aspx页中隐藏超链接.如何执行此操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的母版页中有一个超级链接,我没有该链接的ID..我需要隐藏当前aspx页中的超链接.该怎么办?



我的aspx代码


I have an hyperLink in master page i don''t have id for that link ..I need to hide hyperlink from my current aspx page.How can I do this?



my aspx code


protected void Page_Load(object sender, EventArgs e)
{
a = (string)Session["userrole"];
if (a == "Parent")
{
   // i need to show the link   
}
else if (a == "Student")
{
// i need to hide the link
}
}

推荐答案

选项:
1.继续并为其输入ID.有没有理由吗?
2.如果要访问文件后面的服务器端代码上的控件,请确保在其中提供"runat=server".定义后,您可以直接在后面的代码中对其进行访问.
3.如果需要,可以将其保留为HTML控件而不是服务器控件,并使用Javascript将其隐藏.在需要时注入可见性错误的Javascript代码.

最后,如果您不太愿意输入ID,请放置一个类或尝试使用jQuery使用各种jQuery选择器(可能适用且可能)访问超链接标签,然后将其隐藏-但这将是客户端解决方案,不是服务器端代码.
Options:
1. Go ahead and give an id to it. Any reason not to?
2. If you want to access a control on server side code behind file then make sure you give ''runat=server'' in it. Once this is defined, you can access it in code behind directly.
3. If you want, you can keep it as HTML control and not a server control and yet hide it using Javascript. Inject the visibility false Javascript code when needed.

Lastly, in case you are too adamant in putting ID, put a class or try to access the hyperlink tag using jQuery using various jQuery selectors (which ever is applicable and possible) , and then hide it - but this would be client side solution and not server side code behind one.


这篇关于我的母版页中有一个超链接,我没有该链接的ID ..我需要从当前的aspx页中隐藏超链接.如何执行此操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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