开发者

How can I refresh label

I have a label that refresh using jQuery. But when I t开发者_高级运维ry to get this value from code behind I have empty text (On Button click). When I using text box everything is ok and when I put enabled = false to text box I also have empty value for this label.

How can I get this value, and have read only control in asp.net?


You will not get any changes made to the Label control on a postback because the state of the Label is not posted. It gets rendered as a <span> tag which is display only and not an input. Any changes you want posted back must be done by:

  1. Adding the value to an input control (eg. hidden, textbox, etc)
  2. Perform an ajax call when changing the label to send the data server side and from there you can store the change however you like (session, db, etc)
  3. Adding the value to the PostBack arguments for the button by doing the PostBack yourself (__doPostBack('yourControl', parameter) this is not recommended)


You need to use a hidden field on the form. Label values are not posted to the server.


use CssClass in Label

<asp:TextBox ID="TextBox1" runat="server" CssClass="invisible" />

<style>
.invisible
{
    display:none;
}
</style>

for getting this value from code behind

<script type="text/javascript">
var str = $('#<%= TextBox1.ClientID %>').html();
alert('str');
</script>

it might work works well when i use Label instead of TextBox

this comment box is not showing what i ve written,wth modify it,

var str=$('#<%=TextBox1.ClientID %>').html();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜