在不使用AutoPostBack的情况下格式化文本框。 [英] Formatting a textbox without using AutoPostBack.

查看:68
本文介绍了在不使用AutoPostBack的情况下格式化文本框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页表单,上面有两个文本框。我在Web表单上还有一个用于文本框的RangeValidator。



以下是RangeValidator的属性:

I have a web form that has two textboxes on it. I also have a RangeValidator on the web form for the textboxes.

Here is the properties for the RangeValidator:

<asp:RangeValidator ID="RangeValidator1" runat="server" 

                    ControlToValidate="TextBox2" CssClass="style40" 

                    ErrorMessage="20% Difference. Please verify numbers" ForeColor="Red" 

                    Type="Integer" Enabled="True" Display="Dynamic"></asp:RangeValidator>





Textbox2属性:



Textbox2 properties:

<asp:TextBox ID="TextBox2" runat="server" Width="180px" AutoPostBack="False" 

                    ontextchanged="TextBox2_TextChanged">0</asp:TextBox>





Textbox1是来自数据库的数据。

Textbox1属性:



Textbox1 is data from the database.
Textbox1 properties:

<asp:TextBox ID="TextBoxLYFTUG" runat="server" Width="180px" 

                    ReadOnly="True" Enabled="False"></asp:TextBox>





以下是RangeValidator背后的代码:



Here is the code behind for the RangeValidator:

double txtVal6 = Convert.ToDouble(TextBox1.Text);
        double minVal6 = (txtVal * 0.8);
        double maxVal6 = (txtVal * 1.2);
        RangeValidator1.MinimumValue = minVal6.ToString();
        RangeValidator1.MaximumValue = maxVal6.ToString();







因为代码是正确的现在它工作正常。 RangeValidator触发错误消息。



应用textbox2的格式代码并将AutoPostBack设置为True时,RangeValidator不会触发,但数据已格式化。



这是格式代码:




As the code is right now it works fine. The RangeValidator fires the error message.

When apply the format code for textbox2 and setting the AutoPostBack to True, the RangeValidator does not fire but the data is formatted.

Here is the format code:

TextBox1.Text = string.Format("{0:0,0}", double.Parse(TextBox1.Text));





有没有办法保持格式并激活验证器点?或者是否有更好的解决方法?



Is there a way to keep the format and fire the validator on point? Or is there a work around that will work better?

推荐答案

您可以使用AJAX来更新特定控件。我在我的几个解决方案中使用过该方法。
You could use AJAX to just update the specific control. I have used that method in several of my solutions.


这篇关于在不使用AutoPostBack的情况下格式化文本框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆