Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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
Asp.net 对多个按钮执行验证_Asp.net - Fatal编程技术网

Asp.net 对多个按钮执行验证

Asp.net 对多个按钮执行验证,asp.net,Asp.net,我在表单中有两部分元素(例如比萨饼和汉堡) 每个部分都有不同的字段,每个部分都有自己的提交按钮。 现在,我只想在按下相应的提交按钮时验证这些部分。如果按下“其他提交”按钮,则不应验证元素的其他部分 <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:Panel ID="Panel2" runat="server" GroupingText="Bur

我在表单中有两部分元素(例如比萨饼和汉堡)

每个部分都有不同的字段,每个部分都有自己的提交按钮。 现在,我只想在按下相应的提交按钮时验证这些部分。如果按下“其他提交”按钮,则不应验证元素的其他部分

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
        <asp:Panel ID="Panel2" runat="server" GroupingText="Burger" BackImageUrl="~/finalll/check 24/check 24/images/background-burger.jpg"
            Width="684px">
            <asp:Label ID="burgertype" runat="server" Text="Burger Type" Width="249px"></asp:Label><br />
            <asp:DropDownList ID="DropDownListburger" AppendDataBoundItems="true" runat="server"
                OnLoad="DropDownListburger_Load">
                <asp:ListItem Text="<Select One>" Value="" />
            </asp:DropDownList>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorbtype" runat="server" InitialValue=""
                ControlToValidate="DropDownListburger" ForeColor="Red" ErrorMessage="*"></asp:RequiredFieldValidator>
            <br />
            <asp:Label ID="burgersize" runat="server" Text="Burger Size" Width="249px"></asp:Label><br />
            <asp:DropDownList ID="DropDownbsize" runat="server">
                <asp:ListItem Text="Select One" Value=""></asp:ListItem>
                <asp:ListItem Text="small" Value="small"></asp:ListItem>
                <asp:ListItem Text="medium" Value="medium"></asp:ListItem>
                <asp:ListItem Text="large" Value="large"></asp:ListItem>
                <asp:ListItem Text="Extra Large" Value="Extra Large"></asp:ListItem>
            </asp:DropDownList>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorbsize" runat="server" InitialValue=""
                ControlToValidate="DropDownbsize" ForeColor="Red" ErrorMessage="*"></asp:RequiredFieldValidator>
            <br />
            <asp:Label ID="Labelquantity2" runat="server" Text="Quantity" Width="249px"></asp:Label><br />
            <asp:TextBox ID="TextBoxquantity2" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorquanty2" runat="server" Text="*"
                ControlToValidate="TextBoxquantity2" ForeColor="Red"></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidatorquanty2" runat="server"
                ErrorMessage="Enter Valid Quantity" ControlToValidate="TextBoxquantity2" CssClass="requiredFieldValidateStyle"
                ForeColor="Red" ValidationExpression="[0-9]+">
            </asp:RegularExpressionValidator>
            <br />
            <asp:Button ID="Buttonburger" runat="server" Text="submit" OnClick="Buttonburger_Click" />
        </asp:Panel>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Buttonburger" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Panel ID="Panel1" runat="server" GroupingText="Pizza" BackImageUrl="~/finalll/check 24/check 24/images/1380310811-pitstsa-ch1--39.jpg"
            Width="684px">
            <asp:Label ID="Pizzatype" Text="Pizza Type" runat="server"></asp:Label>
            <br />
            <asp:DropDownList ID="dropdwnpizza" AppendDataBoundItems="true" runat="server" OnLoad="dropdwnpizza_Load">
                <asp:ListItem Text="<Select One>" Value="" />
            </asp:DropDownList>
            <asp:RequiredFieldValidator ID="rfqdropdwnpizza" runat="server" InitialValue="" ControlToValidate="dropdwnpizza"
                ForeColor="Red" ErrorMessage="*"></asp:RequiredFieldValidator>
            <br />
            <asp:Label ID="pizzasize" Text="Pizza Size" runat="server"></asp:Label><br />
            <asp:DropDownList ID="DropDwnsize" runat="server">
                <asp:ListItem Text="Select One" Selected="True" Value=""></asp:ListItem>
                <asp:ListItem Text="small" Value="small"></asp:ListItem>
                <asp:ListItem Text="medium" Value="medium"></asp:ListItem>
                <asp:ListItem Text="large" Value="large"></asp:ListItem>
                <asp:ListItem Text="Extra Large" Value="Extra Large"></asp:ListItem>
            </asp:DropDownList>
            <asp:RequiredFieldValidator ID="rfqpizzasize" runat="server" InitialValue="" ControlToValidate="DropDwnsize"
                ForeColor="Red" ErrorMessage="*"></asp:RequiredFieldValidator>
            <br />
            <asp:Label ID="Labelquantity" runat="server" Text="Quantity" Width="249px"></asp:Label><br />
            <asp:TextBox ID="TextBoxquantity" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="pprc" runat="server" Text="*" ControlToValidate="TextBoxquantity"
                ForeColor="Red"></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidatorpprc" runat="server"
                ErrorMessage="Enter Valid Quantity" ControlToValidate="TextBoxquantity" CssClass="requiredFieldValidateStyle"
                ForeColor="Red" ValidationExpression="[0-9]+">
            </asp:RegularExpressionValidator>
            <asp:Button ID="Buttonpizza" runat="server" Text="submit" OnClick="Buttonpizza_Click" />
        </asp:Panel>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Buttonpizza" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>













您需要使用验证组,从-

验证组允许您在页面上组织验证控件 作为一个整体。每个验证组都可以独立执行验证 来自页面上的其他验证组

例如(来自MSDN):


试着将代码向左移动:)
<asp:requiredfieldvalidator id="RequiredFieldValidator2"
      controltovalidate="AgeTextBox"
      validationgroup="PersonalInfoGroup"
      errormessage="Enter your age."
      runat="Server">
 </asp:requiredfieldvalidator>

 <!--When Button1 is clicked, only validation controls that are a part of PersonalInfoGroup
     are validated.-->
 <asp:button id="Button1" 
      text="Validate" 
      causesvalidation="true"
      validationgroup="PersonalInfoGroup"
      runat="Server" />