Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么asp.net c ValidationSummary显示多个消息框?_C#_Asp.net_Webforms - Fatal编程技术网

C# 为什么asp.net c ValidationSummary显示多个消息框?

C# 为什么asp.net c ValidationSummary显示多个消息框?,c#,asp.net,webforms,C#,Asp.net,Webforms,事情是这样的。我有一个C语言的ASP.NET Web应用程序。在Default.aspx中,我有一个包含所有元素的UpdatePanel。在那里,我有三个与文本框关联的验证器,4个单选按钮,两个属于一个组,另外两个属于另一个组,对于每个组,我有一个验证器,以验证是否为每个组检查了一个元素。对于所有RadioButton,AutoPostBack设置为True,因为当两个组都选择了No选项时,我将启用多行文本框,以便用户可以输入一些文本。最后还有一个ValidationSummary,它在弹出框和

事情是这样的。我有一个C语言的ASP.NET Web应用程序。在Default.aspx中,我有一个包含所有元素的UpdatePanel。在那里,我有三个与文本框关联的验证器,4个单选按钮,两个属于一个组,另外两个属于另一个组,对于每个组,我有一个验证器,以验证是否为每个组检查了一个元素。对于所有RadioButton,AutoPostBack设置为True,因为当两个组都选择了No选项时,我将启用多行文本框,以便用户可以输入一些文本。最后还有一个ValidationSummary,它在弹出框和页面中显示错误消息。主要问题如下:如果我首先从单选按钮中选择两个选项,然后单击提交按钮,而没有在带有3个验证程序的文本框中输入任何文本,我将得到3条弹出错误消息。更有趣的是,如果我在3个弹出错误消息之后从任何RadioButton组中选择另一个选项,我将得到4个弹出错误消息。我猜测这与RadioButton的AutoPostBack属性有关,因为它发生在我单击它们时,但我不知道为什么或如何修复它

以下是Default.aspx的代码:


任何帮助都将受到感谢,批评人士也将受到欢迎。谢谢。

你确定这是真的吗?你将单选按钮设置为post back true并将其放入触发器中?我已经尝试了所有方法,包括最后一段代码。现在我从UpdatePanel中取出了ValidationSummary,当ID的文本框为空时,没有显示多个弹出消息,但当我取消标记所有单选按钮时,它不会弹出任何错误消息,它只在按钮后的摘要中显示消息。但是,我仍然不明白为什么。在您的原始代码中,请删除触发器标记并再次测试。当我删除触发器时,它仍然会弹出多条消息。事实上什么都没有改变。我知道这并不能回答我仍在研究的问题,但我突然想到,在使用自定义验证器的ClientValidationScript属性的javascript/jquery函数中,这将更有效。总比依靠回邮好。还在看你的问题。。。。
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>

        <asp:Label ID="Label1" runat="server" Text="M-DCPS 7-digit Student ID#:"></asp:Label>            
        <asp:TextBox ID="studentIDtbox" runat="server" MaxLength="7" Width="6%" CausesValidation="false"></asp:TextBox>
        <asp:RequiredFieldValidator Font-Size="Large" ID="RequiredFieldValidatorAccount" runat="server" ControlToValidate="studentIDtbox" 
            ErrorMessage="ID# required" ForeColor="Red">*</asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator Font-Size="Large" ID="RegularExpressionValidator2" runat="server" ControlToValidate="studentIDtbox" ErrorMessage=" ID requires 7 digits" ValidationExpression="^[\s\S]{7,}$" ForeColor="Red">*</asp:RegularExpressionValidator>
        <asp:RegularExpressionValidator Font-Size="Large" ID="RegularExpressionValidator1" runat="server" ControlToValidate="studentIDtbox" 
            ErrorMessage=" ID only accepts numbers" ValidationExpression="^\d+$" ForeColor="Red">*</asp:RegularExpressionValidator>

        <asp:Label ID="Label2" runat="server" Text="Paper Form:"></asp:Label>            
        <asp:DropDownList ID="paperForm" runat="server"></asp:DropDownList>

        <asp:Label ID="Label3" runat="server" Text="Paper Accommodation:"></asp:Label>
        <asp:DropDownList ID="paperType" runat="server"></asp:DropDownList>

        <asp:CustomValidator Font-Size="Large" runat="server" ID="cvIEP" OnServerValidate="cvIEP_ServerValidate" 
            Enabled="true" Display="Dynamic" SetFocusOnError="true" ErrorMessage="You must select at least one item for documentation on IEP/Section 504." ForeColor="Red">*</asp:CustomValidator>
        <asp:Label ID="Label4" runat="server" Text="Paper is documented?"></asp:Label>

        <asp:RadioButton ID="iepYesRb" runat="server" GroupName="IEPRequirement" Text="Yes" OnCheckedChanged="rButton_CheckedChanged" AutoPostBack="True" CausesValidation="false"/>

        <asp:RadioButton ID="iepNoRb" runat="server" GroupName="IEPRequirement" Text="No" OnCheckedChanged="rButton_CheckedChanged" AutoPostBack="True" CausesValidation="false"/>

        <asp:CustomValidator Font-Size="Large" runat="server" ID="cvRuse" OnServerValidate="cvRuse_ServerValidate" 
            Enabled="true" SetFocusOnError="true" ErrorMessage="You must select at least one item for regular use." ForeColor="Red">*</asp:CustomValidator>
        <asp:Label ID="Label5" runat="server" Text="Is it used regularly?"></asp:Label>

        <asp:RadioButton ID="ruseYesRb" runat="server" GroupName="RegularUse" Text="Yes" OnCheckedChanged="rButton_CheckedChanged" AutoPostBack="True" CausesValidation="false"/>

        <asp:RadioButton ID="ruseNoRb" runat="server" GroupName="RegularUse" Text="No" OnCheckedChanged="rButton_CheckedChanged" AutoPostBack="True" CausesValidation="false"/>            

        <asp:Label ID="Label6" runat="server" Text="Provide other evidence if two 'No' where selected."></asp:Label>

        <asp:TextBox ID="evidenceTbox" Style="height: 130px" runat="server" TextMode="MultiLine" Width="100%" Enabled="false"></asp:TextBox>

        <asp:Button ID="submitButton" runat="server" Text="Submit" OnClick="submit_OnClick" />

        <asp:ValidationSummary ID="valTest" runat="server" ShowMessageBox="true" BackColor="LightYellow" ForeColor="Red" Width="100%" />

    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="submitButton" />
        <asp:AsyncPostBackTrigger ControlID="iepYesRb" EventName="CheckedChanged" />
        <asp:AsyncPostBackTrigger ControlID="iepNoRb" EventName="CheckedChanged" />
        <asp:AsyncPostBackTrigger ControlID="ruseYesRb" EventName="CheckedChanged" />
        <asp:AsyncPostBackTrigger ControlID="ruseNoRb" EventName="CheckedChanged" />
    </Triggers>
</asp:UpdatePanel>
    protected void rButton_CheckedChanged(object sender, EventArgs e)
    {
        evidenceTbox.Enabled = iepNoRb.Checked && ruseNoRb.Checked;
    }

    protected void cvIEP_ServerValidate(object sender, ServerValidateEventArgs e)
    {
        e.IsValid = iepNoRb.Checked || iepYesRb.Checked;
    }

    protected void cvRuse_ServerValidate(object sender, ServerValidateEventArgs e)
    {
        e.IsValid = ruseNoRb.Checked || ruseYesRb.Checked;
    }

    protected void submit_OnClick(object sender, EventArgs e)
    {

        if (Page.IsValid)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alerts", "javascript:alert('Record inserted properly')", true);
        }
    }