标签文本没有进入aspx.cs页面 [英] label text not getting in the aspx.cs page
问题描述
大家好,
我正在使用jquery自动完成文本框来搜索Username.Also我使用jquery将userID存储在标签中。当我运行时应用程序,userid将出现在标签控件中。但是当我尝试使用此label.text进行插入时,它显示一个空字符串。如何在aspx.cs页面中获取标签文本..它很棒很高兴得到这个解决方案
提前谢谢
我猜当页面回发时标签文本属性被page_load / page_init事件覆盖。你只需检查它,如果需要,在更新文本属性之前添加page.IsPostBack条件。$
< script type = text / javascript>
function setValue(){
( [id * = lblData])。text( 100\" 跨度>);
}
< / script>
< input type = buttonid =btnSetValuevalue =Set Valueonclick =setValue(); />
受保护 < span class =code-keyword> void
page_load( object sender,EventArgs e)
{
if (!base.IsPostBack){
lblData.Text = string .empty;
}
}
从按钮事件处理程序访问此属性
< pre lang =c#> protected void btnSave_Clicked( object sender,EventArgs e)
{
string value = lblData 。文本;
}
Hi All,
I am using jquery auto complete textbox to search Username.Also I store userID in the label by using the jquery.When I am running the application, userid will appear in the label control.But when I try to use this label.text for insertion purpose, it is showing an empty string.How can I get the label text in the aspx.cs page also..It s great pleasure to get a solution on this
Thanks in advance
I guess when page is postback then Label text property is overridden by page_load/page_init event. you just check it and if needed add page.IsPostBack condition before update text property.i.e
<script type="text/javascript"> function setValue(){
("[id*=lblData]").text("100"); } </script>
<input type="button" id="btnSetValue" value="Set Value" onclick="setValue();" />
protected void page_load(object sender, EventArgs e) { if(!base.IsPostBack){ lblData.Text = string.empty; } }
access this property from a button event handler
protected void btnSave_Clicked(object sender, EventArgs e) { string value = lblData.Text; }
这篇关于标签文本没有进入aspx.cs页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!