问题描述
我必须能够隐藏/取消隐藏标签客户端.该标签必须首先隐藏,并且我无法将Visible属性设置为false,因为随后从html中删除了该控件.我尝试通过调用javascript服务器端来加载页面时隐藏标签:
I must be able to hide/unhide a label clientside. The label must be hidden at first and I can''t set the Visible property to false because then the control is removed from html. I try to hide the label when a page is loaded by calling javascript serverside:
protected void Page_Unload(object sender, EventArgs e)
{
//hide case number label
this.Page.ClientScript.RegisterClientScriptBlock(typeof(string), "hidelabel", "<script language=javascript>$get(''" +
"ContentPlaceHolder1_lblCase'').style.display = ''none'';</script>");
}
这是行不通的-没有任何反应.请告诉我我在做什么错.
This doesn''t work - nothing happens. Please tell me what I''m doing wrong.
推荐答案
这是行不通的-没有任何反应.请告诉我我在做错什么.
This doesn''t work - nothing happens. Please tell me what I''m doing wrong.
.hidden
{
display: none;
}
然后,直接将样式应用于标签HTML
Then, either apply the style to the label HTML directly
<asp:Label id="label1"
CssClass="hideen"
runat="server" />
...或根据某些先决条件在您的代码中应用
...or apply in your code based on some precondition
protected void Page_Load(object sender, EventArgs e)
{
if (SomethingToTest)
{
label1.CssClass = "hidden";
}
}
protected void Page_Unload(object sender, EventArgs e)
{
//hide case number label
this.Page.ClientScript.RegisterClientScriptBlock(typeof(string), "hidelabel", "<script language="javascript">
这篇关于隐藏标签-调用JavaScript服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!