为什么文本框的ontextchanged事件在回发后不起作用 [英] Why ontextchanged event of textbox isnot working after postback
问题描述
文本框的为什么ontextchanged事件状态并没有回发后
工作<预LANG = XML> <跨度类= 代码关键字>< 跨度> <跨度类= 代码leadattribute> DIV 跨度> <跨度类= 代码属性> 跨度> <跨度类= 代码属性>类跨度> <跨度类= code-keyword> = col-md-6 >
<跨度类= 代码关键字>< 跨度> <跨度类= 代码leadattribute> ASP:文本框跨度> <跨度类= 代码属性> ID = txtname runat = server class = form-control
< span class =code-attribute> meta:resourcekey = txtnameResource1 AutoPostBack = True ontextchanged = txtname_changed > < / asp:TextBox >
< asp:RequiredFieldValidator ID = ReqName runat = server
ControlToValidate = txtname 显示 = 动态
ErrorMessage = 请输入名称
meta:resourcekey = RequiredFieldValidator3Resource1 > < / asp:RequiredFieldValidator >
< / div >
< span class =code-keyword> protected void t xtname_changed( object sender,EventArgs e)
{
int Count = m。 bussinesCollection.SubscriptionKindBL.GetSubscriptionkindbyname(txtname.Text.ToString());
if (Count!= 0 )
{
lblmessage.Visible = true ;
lblmessage.Text = 用户名已存在;
}
else
{
lblmessage.Visible = 假跨度>;
m.bussinesCollection.SubscriptionKindBL.Name = txtname.Text;
}
}
我的代码工作正常,但在调试过程中我发现,当我在文本框中更改值时,如果它是repatly来,那么vaLUE就不能改变。
和没有页面刷新我就无法输入新值。
Ex。假设我在这个文本框中输入Asp.net,如果asp.net已经输入意味着它存在于数据库中,则显示labelmsg。但是当我尝试更改此值时,我发现如果我输入任何值,如abcd那么textbox的值重复成为Asp.net,直到我没有翻页。
任何人都可以给我解决方案。
提前致谢。
显示错误消息&如果您想显示输入的文本值,请在错误消息中显示它,例如
lblmessage.Text = '您输入的文字'已存在;
将文本框的属性更改为enableViewState = false并且AutoPostback = true
尝试在另一个页面上单独实现此功能,如果有效,则原始页面中的其他因素可能会影响功能。因为当我这样做时,我没有找到这种类型的问题。
Why ontextchanged event of textbox isnot working after postback
<div class="col-md-6">
<asp:TextBox ID="txtname" runat="server" class="form-control"
meta:resourcekey="txtnameResource1" AutoPostBack="True" ontextchanged="txtname_changed"></asp:TextBox>
<asp:RequiredFieldValidator ID="ReqName" runat="server"
ControlToValidate="txtname" Display="Dynamic"
ErrorMessage="Please Enter Name"
meta:resourcekey="RequiredFieldValidator3Resource1"></asp:RequiredFieldValidator>
</div>
protected void txtname_changed(object sender, EventArgs e)
{
int Count = m.bussinesCollection.SubscriptionKindBL.GetSubscriptionkindbyname(txtname.Text.ToString());
if (Count != 0)
{
lblmessage.Visible = true;
lblmessage.Text = "User Name is Already Exist";
}
else
{
lblmessage.Visible = false;
m.bussinesCollection.SubscriptionKindBL.Name = txtname.Text;
}
}
my code works fine but during debugging i found that,when i change value in textbox if it is repatly come then that vaLUE CAN'T CHANGE.
and i can't enter new value without page refresh.
Ex. suppose i enter Asp.net in this textbox,if asp.net is already enter means it is exist in database,then labelmsg is shown.but when i try to change this value i found that if i enter any value like abcd then textbox's value become Asp.net repeatly till i not page refresh.
can anyone give me solution for that.?
Thanks in advance.
Make Text Box blank after showing error message & if u want to show entered text value also then make it visible in your error message like
lblmessage.Text = "'Your entered text' is Already Exist";
Change the property of your text box to enableViewState=false and AutoPostback=true
try to implement this separately on another page,if works then may other factors from original page are affecting functionality. Because when i done this, i not found such type of issue.
这篇关于为什么文本框的ontextchanged事件在回发后不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!