Asp.Net如何使用javascript隐藏标签 [英] Asp.Net How to hide label using javascript

查看:47
本文介绍了Asp.Net如何使用javascript隐藏标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何在asp.net中使用javascript清除标签文字..?



我想清除按钮上的标签文本(asp:按钮)单击,通过调用java脚本函数。



我试过

Hi All,
How can I clear label text using javascript in asp.net..?

I want to clear the text of my Label on Button(asp:Button) Click, by calling a java script function.

I tried

document.getElementByID("label1").innerHTML='';



它已清除,但由于回发,它突然恢复了价值。

i不能在页面加载中使用以下代码


It cleared,but suddenly it getting the value back,because of postback..
i can''t use these following code in page load

if (!IsPostBack)
{
   label1.Text = "";
}



任何其他选项。否则告诉我如何隐藏Button上的标签(asp:Button)点击,通过调用java脚本函数。

我用这些代码隐藏

var obj = document.getElementById(label1);

obj.style.display =none;

obj.style.visibility =hidden;

再次因为回发而在我的情况下不起作用。



请帮我...

谢谢,

Vineetha.KR


any other option for this. Otherwise tell me how can i hide the label on Button(asp:Button) Click, by calling a java script function.
I used these code to hide
var obj = document.getElementById("label1");
obj.style.display = "none";
obj.style.visibility = "hidden";
Again it''s not working in my case because of postback.

Pls help me...
Thanks ,
Vineetha.K.R

推荐答案

您可以尝试使用以下代码隐藏控件。



You can try hiding the control with following code.

var obj = document.getElementById("label1");
obj.style.display = "none";
obj.style.visibility = "hidden";





另外,你可以把它隐藏在Page_Load



ie label1.Visible = false;



不是吗?



希望有所帮助。如果没有,请将其标记为答案/ upvote。

-Milind



Also, you can hide it On Page_Load

i.e. label1.Visible=false;

Isnt it?

Hope that helps. If it doesn, mark it as answer/upvote.
-Milind


试试这个





var obj = document.getElementById(<%= label1.ClientID%>);

obj.style.display =''none'';
Try this


var obj = document.getElementById("<%=label1.ClientID %>");
obj.style.display = ''none'';


是的,你的标签在回发上保持其值的原因是因为你正在调用一些方法来填充PageLoad事件上的标签'的值。包含此代码

Yes, the reason your label is persisting its value on postback is because you are calling some method that populates the label''s value on PageLoad event. Wrap this code inside
if(!IsPostBack)
{
//call function to populate the values
}

在按钮上单击事件清除标签的价值

On buttons click event clear the label''s value

Protected Void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "";
}

如果你想再次填充值而没有标签持久化它的值:

and if you want to populate the values again without the label persisting its value use:

Protected Void Button1_Click(object sender, EventArgs e)
{
//call function to populate the values
Label1.Text = "";
}Hope it helps. If it doesn't work post your complete code.


这篇关于Asp.Net如何使用javascript隐藏标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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