为什么文本框格式触发验证器? [英] Why is textbox format firing validators?

查看:62
本文介绍了为什么文本框格式触发验证器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页表单,上面有八个文本框和八个范围验证器。当用户输入他们的数据时,数字的格式在文本框文本更改为逗号。这是我正在使用的格式代码:



I have a web form that has eight textboxes and eight rangevalidators on it. When a user enters their data the numbers are formatted on textbox text change with commas. Here is the format code I am using:

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





格式工作正常,直到用户点击提交八个验证器中有四个发射。可能导致验证器触发的原因以及如何解决?





The format works fine until the user clicks on submit and four out of eight validators fire. What could have caused the firing of the validators and how can I fix it?

protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        RangeValidator1.Validate();
        TextBox1.Text = string.Format("{0:0,0}", Int32.Parse(TextBox1.Text));
        TextBox2.Focus();
    }

推荐答案

Tente usar o mesmo CultureInfo tanto no validador quanto no String.Format



例如:



Tente usar o mesmo CultureInfo tanto no validador quanto no String.Format

Ex.:

Convert.ToDecimal(TextBox.Text).ToString(CultureInfo.GetCultureInfo("en-US"))


这篇关于为什么文本框格式触发验证器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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