单击“提交按钮”时,为什么RangeValidator会触发? [英] Why do RangeValidator fire when Submit Button is click?

查看:83
本文介绍了单击“提交按钮”时,为什么RangeValidator会触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页表单,上面有八个文本框和八个范围验证器。当用户输入数据并且一切正确时,用户单击提交按钮,即使数据正确,也会触发四个范围验证器。为什么会发生这种情况?



以下是四个RangeValidators的属性:

 <   asp:RangeValidator     ID   =  RangeValidator1    runat   =  server    

< span class =code-attribute> ControlToValidate = TextBox1 < span class =code-attribute> CssClass = style40

ErrorMessage = 20%的差异。请验证数字 ForeColor = 红色

类型 = 整数 已启用 = True 显示 = 动态 > < / asp:RangeValidator >



 <   asp:RangeValidator     ID   =   RangeValidator2    runat   =  server    

ControlToVal idate = TextBox2 CssClass = style40

ErrorMessage = 20%差异。请验证数字 ForeColor = 红色

类型 = 整数 已启用 = True 显示 = 动态 > < / asp:RangeValidator >



 <   asp:RangeValidator     ID   =   RangeValidator3    runat   =  server    

ControlToVal idate = TextBox3 CssClass = style40

ErrorMessage = 如果一个机构经历了委员会下面定义的显着入学增长,委员会有义务监督机构计划的发展。根据一般入学信息机构概况中的报告,显着的入学人数增长是一年内总全日同等入学人数增加40%或更多。 ForeColor = 红色 类型 = 整数 已启用 = True 显示 = 动态 > < / asp:RangeValidator >



 <   asp:RangeValidator     ID   =  RangeValidator4    runat   = 服务器    

< span class =code-attribute> < span class =code-attribute> ControlToValidate = TextBox4 CssClass = style40 显示 = 动态 ErrorMessage = 如果提供远程或函授教育课程的机构在一个会计年度内人员入学人数增加50%或以上联邦政策要求委员会在获取此类数据后30天内向教育部长报告该信息。 ForeColor = 红色 style = font-weight:700 类型 = < span class =code-keyword>整数 > < / asp:RangeValidator >





以下是执行计算的代码:

< pre lang =c#> int itxtVal1 = Convert.ToInt32(TextBox1A.Text.Replace( < span class =code-string>,, ));
int iminVal1 =(itxtVal1 - itxtVal1 * 20 / 100 );
int imaxVal1 =(itxtVal1 + itxtVal1 * 20 / 100 );
RangeValidator1.MinimumValue = iminVal1.ToString();
RangeValidator1.MaximumValue = imaxVal1.ToString();



  int  itxtVal1 = Convert.ToInt32(TextBox2A.Text.Replace(  )); 
int iminVal1 =(itxtVal1 - itxtVal1 * 20 / 100 );
int imaxVal1 =(itxtVal1 + itxtVal1 * 20 / 100 );
RangeValidator2.MinimumValue = iminVal1.ToString();
RangeValidator2.MaximumValue = imaxVal1.ToString();



  int  itxtVal6 = Convert.ToInt32(TextBox3A.Text.Replace(  )); 
int iminVal6 = 0 ;
int imaxVal6 =(itxtVal6 + itxtVal6 * 40 / 100 );
RangeValidator3.MinimumValue = iminVal6.ToString();
RangeValidator3.MaximumValue = imaxVal6.ToString();



  int  itxtVal6 = Convert.ToInt32(TextBox4A.Text.Replace(  )); 
int iminVal6 = 0 ;
int imaxVal6 =(itxtVal6 + itxtVal6 * 50 / 100 );
RangeValidator4.MinimumValue = iminVal6.ToString();
RangeValidator4.MaximumValue = imaxVal6.ToString();

解决方案

在范围验证器的MaximumValue和设置上设置断点看看它的目的是什么。



我的猜测是文本框转换为整数是否为零?


I have a web form that has eight textboxes and eight rangevalidators on it. When a user enters their data and everything is correct, the user clicks the Submit button and four of the rangevalidator fires even when the data is correct. Why does this happen?

Here are the properties of the four RangeValidators:

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

                    ControlToValidate="TextBox1" CssClass="style40" 

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

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


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

                    ControlToValidate="TextBox2" CssClass="style40" 

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

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


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

                    ControlToValidate="TextBox3" CssClass="style40" 

                    ErrorMessage="If an institution experiences significant enrollment growth as defined as below by the Commission, the Commission is obligated to monitor the growth of the institution's programs. Significant enrollment growth is a total full-time equivalent enrollment increase of 40 percent or more within one year as reported on the Institutional Profile for General Enrollment Information." ForeColor="Red" Type="Integer" Enabled="True" Display="Dynamic"></asp:RangeValidator>


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

                        ControlToValidate="TextBox4" CssClass="style40" Display="Dynamic" ErrorMessage="If an institution that offers distance or correspondence education courses has experienced an increase in headcount enrollment of 50 percent or more within one fiscal year, federal policy requires the Commission to report that information to the Secretary of Education within 30 days of acquiring such data." ForeColor="Red" style="font-weight: 700" Type="Integer"></asp:RangeValidator>



Here are the codes that do calculation behind:

int itxtVal1 = Convert.ToInt32(TextBox1A.Text.Replace(",", ""));
        int iminVal1 = (itxtVal1 - itxtVal1 * 20 / 100);
        int imaxVal1 = (itxtVal1 + itxtVal1 * 20 / 100);
        RangeValidator1.MinimumValue = iminVal1.ToString();
        RangeValidator1.MaximumValue = imaxVal1.ToString();


int itxtVal1 = Convert.ToInt32(TextBox2A.Text.Replace(",", ""));
        int iminVal1 = (itxtVal1 - itxtVal1 * 20 / 100);
        int imaxVal1 = (itxtVal1 + itxtVal1 * 20 / 100);
        RangeValidator2.MinimumValue = iminVal1.ToString();
        RangeValidator2.MaximumValue = imaxVal1.ToString();


int itxtVal6 = Convert.ToInt32(TextBox3A.Text.Replace(",", ""));
        int iminVal6 = 0;
        int imaxVal6 = (itxtVal6 + itxtVal6 * 40 / 100);
        RangeValidator3.MinimumValue = iminVal6.ToString();
        RangeValidator3.MaximumValue = imaxVal6.ToString();


int itxtVal6 = Convert.ToInt32(TextBox4A.Text.Replace(",", ""));
        int iminVal6 = 0;
        int imaxVal6 = (itxtVal6 + itxtVal6 * 50 / 100);
        RangeValidator4.MinimumValue = iminVal6.ToString();
        RangeValidator4.MaximumValue = imaxVal6.ToString();

解决方案

Put a breakpoint on the setting of the range validator's MaximumValue and see what it is being set to.

My guess would be that the textbox conversion to integer is returning zero?


这篇关于单击“提交按钮”时,为什么RangeValidator会触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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