[英]Update panel textchanged problem asp.net c#
After leaving the textbox, I want it to focus on the next object.离开文本框后,我希望它专注于下一个 object。 Or I want the button to work when I click the button.或者我希望按钮在单击按钮时起作用。 In the problem I'm having right now, I'm having the problem in the gif after leaving the textbox.在我现在遇到的问题中,离开文本框后我在 gif 中遇到了问题。
default.aspx默认.aspx
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<div class="form-group row">
<label class="col-lg-2 col-form-label">İşlem Tutarı</label>
<div class="col-lg-4">
<asp:TextBox ID="txtTutar" CssClass="form-control form-control-sm price" AutoPostBack="true" placeholder="0,00 ₺" runat="server" OnTextChanged="txtTutar_TextChanged"></asp:TextBox>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label">Tahsil Edilen Tutar</label>
<div class="col-lg-4">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtTahsilEdilen" AutoPostBack="true" CssClass="money form-control form-control-sm price" placeholder="0,00 ₺" runat="server" OnTextChanged="txtTahsilEdilen_TextChanged"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtTutar" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
default.asp.cs默认.asp.cs
protected void txtTutar_TextChanged(object sender, EventArgs e)
{
txtTutar.Text = FormatMoney(decimal.Parse(txtTutar.Text));
txtTahsilEdilen.Text = txtTutar.Text;
}
I would do one of several things.我会做几件事之一。 First up, with the post back occurring (text changed), then when you click on another control - you would in theory have to click two times.首先,发生回发(文本已更改),然后当您单击另一个控件时 - 理论上您必须单击两次。
So, either remove the text changed post-back, and format the number WHEN done.因此,要么删除回发更改的文本,然后在完成后格式化数字。 if you really want this to occur during typing, then如果您真的希望在打字过程中发生这种情况,那么
If you using the ajax control toolkit, there is a really nice number/currency formatter.如果您使用 ajax 控制工具包,有一个非常好的数字/货币格式化程序。
if not, then consider a jQuery plugin - it will remove the need for a post-back, and you do this client side.如果没有,那么考虑使用 jQuery 插件——它将消除对回发的需要,而您可以在客户端执行此操作。 there is a REALLY nice JavaScript library here for this:这里有一个非常好的 JavaScript 库:
https://robinherbots.github.io/Inputmask/ https://robinherbots.github.io/Inputmask/
The other easy way - probably the least effort?另一种简单的方法 - 可能是最省力的?
use a ajax call based on text changed.根据更改的文本使用 ajax 调用。 That will allow you to run the code behind for the one text box, and now update panel post-back will NOT occur.这将允许您为一个文本框运行后面的代码,并且现在不会发生更新面板回发。
So you could code out the textbox like this:所以你可以像这样编写文本框:
<br />
<asp:TextBox ID="TextBox2" runat="server" onchange="fixnum(this)"
ClientIDMode="Static"
></asp:TextBox>
<script>
function fixnum(c) {
tBox = $(c)
$.ajax({
type: "POST",
data: JSON.stringify({ v: tBox.val() }),
contentType: "application/json;charset=utf-8",
dataType: "json",
async: true,
url: "WebForm4.aspx/curFormat",
success: function (MyReturn) {
tBox.val(MyReturn.d);
},
failure: function () {
tBox.val("")
}
});
}
</script>
And in the web page, we have:在 web 页面中,我们有:
using System.Web.Services;
And then a public web method, say like this:然后是一个公共的 web 方法,这样说:
[WebMethod]
public static string curFormat(string v)
{
Debug.Print("web call");
v = String.Format("{0:#,##0.00}", double.Parse(v));
return v;
}
So, now when you type in a number, and hit tab - we don't do a post-back but do get to run the code behind stub.所以,现在当你输入一个数字并点击 Tab 时——我们不做回发,而是运行存根后面的代码。 In fact, you probably could wind up as a result removing the whole need for the update panel.实际上,您可能会因此消除对更新面板的全部需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.