更新面板内的文本框仍然刷新整个页面。 [英] Textbox inside update panel is still refreshing whole page.
本文介绍了更新面板内的文本框仍然刷新整个页面。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含大量控件的页面。当我在文本框中键入时,其格式需要更改为格式化文本。我不希望整个页面被刷新。请看下面我的代码...
这不行...请纠正我...在aspx页面
I have a page with lots of controls . When i type inside a textbox its format need to be changes to a formatted text. i don't want the whole page to be refreshed. please see my code below...
this is not working...please correct me...in aspx page
<asp:UpdatePanel runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<fieldset>
<asp:TextBox ID="txtContact" runat="server" ForeColor="#999999"
value="Contact Number" onfocus="if (this.value == 'Contact Number') {this.value = '';this.style.color = '#000000';}"
onblur="if(this.value == '') { this.value='Contact Number';this.style.color ='#999999';}"
Width="165px" AutoPostBack="True" ontextchanged="txtContact_TextChanged" ></asp:TextBox>
<asp:RequiredFieldValidator ID="rContact" runat="server"
ControlToValidate="txtContact" CssClass="failureNotification" ValidationGroup="Contact" ErrorMessage="*"></asp:RequiredFieldValidator>
</fieldset>
</ContentTemplate>
<triggers>
<asp:PostBackTrigger ControlID="txtContact" ></asp:PostBackTrigger>
</triggers>
</asp:UpdatePanel>
代码落后(aspx.cs)
code behind (aspx.cs)
protected void txtContact_TextChanged(object sender, EventArgs e)
{
try
{
if (txtContact.Text != "Contact Number")
{
string x = txtContact.Text;
double y = Double.Parse(x);
txtContact.Text = String.Format("{0:(###) ###-####}", y);
}
}
catch (Exception ex)
{
txtContact.Text = "Contact Number";
}
}
仍然整个页面都是refeshing ...后面的代码工作正常
still the whole page is refeshing...code behind is working perfectly
推荐答案
使用AsyncPostBackTrigger而不是PostBackTrigger。
Use AsyncPostBackTrigger instead of PostBackTrigger.
<asp:AsyncPostBackTrigger ControlID="txtContact" EventName="TextChanged" />
这篇关于更新面板内的文本框仍然刷新整个页面。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文