[英]Master Page label visibility in child page
I want to make a label invisible in child page which is defined in master page. 我想使标签在母版页中定义的子页中不可见。 Is there a way to do that?
有没有办法做到这一点?
((Label)Master.FindControl("mylbl")).Visible = false;
put this in page load of the child page , mylbl
refers to the ID of the label 将其放在子页面的页面加载中,
mylbl
指标签的ID
it might be Master.Page.FindControl ....
now that I think of it, it's been a while , but that's how you do it 可能是
Master.Page.FindControl ....
现在我想到了,已经有一段时间了,但这就是您的做法
You should use javascript. 您应该使用javascript。 Normally in this situation, you would reference your label using (assuming your label's ID is my_label_id)
通常在这种情况下,您可以使用引用标签(假设标签的ID为my_label_id)
document.GetElementById('<%= my_label_id.ClientId %>')
. 。 .
。 .
。 or if you are using jquery .
或者,如果您使用的是jquery。 .
。 .
。
$('#<%= my_label_id.ClientId %>')
However, AFAIK you cannot use clientid to reference a server-side control located on the master page from a content page. 但是,根据AFAIK,您不能使用clientid从内容页面引用位于母版页上的服务器端控件。 So I would either give the control a unique class name using the asp.net label attribute
CssClass="myLabelClass"
or retrieve the client Id by building the page, viewing the source, and finding the client ID. 因此,我要么使用asp.net标签属性
CssClass="myLabelClass"
为控件赋予唯一的类名,要么通过构建页面,查看源代码并找到客户端ID来检索客户端ID。 Steps for this can be found here: How to use javascript in content page, asp.net 可在此处找到相关步骤: 如何在asp.net内容页面中使用javascript
Once you correctly reference the item, simply change the "display" style attribute to "none" as seen below. 正确引用该项目后,只需将“显示”样式属性更改为“无”,如下所示。 Using jQuery and assuming your CssClass name is myLabelClass :
使用jQuery并假设您的CssClass名称为myLabelClass :
$('.myLabelClass').css('display','none');
If you wanted this to occur on page load you could do the following: 如果希望在页面加载时发生这种情况,可以执行以下操作:
$(function(){
$('.myLabelClass').css('display','none');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.