带有母版页的Web表单,不能去购物车

时间:2018-03-09 08:43:21

标签: c# asp.net forms redirect

我有这个页面,它有user.master页面。在用户母版页面上,我有“购物车”按钮和“登录”按钮。 我无法在不填写表单的情况下重定向到提到的页面,是否可以在不填写表单的情况下进行重定向? 请指教,我在网上找不到任何解释。 My screenshot with explenation

<!-- Board Match Start -->
    <div class="container relativeSignUpImage">
        <h3>Board Matcher</h3>
        <h4>The best way to find a board that fits your needs.</h4>
        <asp:Label ID="lblMsg" runat="server"></asp:Label>
        <div class="center-page">
            <label class="col-xs-11">What size of wave will you ride this board on?</label>
            <div class="col-xs-11">
                <%--<asp:RadioButton ID="RadioButton1" runat="server" Text="Knee to waist high" GroupName="wSize" value="1"/>
                    <asp:RadioButton ID="RadioButton2" runat="server" Text="Waist to chest high" GroupName="wSize" value="2"/>
                    <asp:RadioButton ID="RadioButton3" runat="server" Text="Chest to head high" GroupName="wSize" value="3"/>
                    <asp:RadioButton ID="RadioButton4" runat="server" Text="Overhead" GroupName="wSize" value="4"/>
                    <asp:RadioButton ID="RadioButton5" runat="server" Text="Double overhead plus" GroupName="wSize" value="5"/>--%>
                <asp:DropDownList ID="wSize" class="form-control" runat="server">
                    <asp:ListItem Value="0">--Select--</asp:ListItem>
                    <asp:ListItem Value="1">Knee to waist high</asp:ListItem>
                    <asp:ListItem Value="2">Waist to chest high</asp:ListItem>
                    <asp:ListItem Value="3">Chest to head high</asp:ListItem>
                    <asp:ListItem Value="4">Overhead</asp:ListItem>
                    <asp:ListItem Value="5">Double overhead plus</asp:ListItem>
                </asp:DropDownList>    
                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorwSize" CssClass="text-danger" runat="server" ErrorMessage="Please choose wave size" ControlToValidate="wSize"></asp:RequiredFieldValidator>
            </div>
            <label class="col-xs-11">What type of wave do you ride?</label>
            <div class="col-xs-11">
                <asp:DropDownList ID="wType" class="form-control" runat="server">
                    <asp:ListItem Value="0">--Select--</asp:ListItem>
                    <asp:ListItem Value="1">Soft and mushy</asp:ListItem>
                    <asp:ListItem Value="2">Rolling</asp:ListItem>
                    <asp:ListItem Value="3">Pitching and fast breaking</asp:ListItem>
                    <asp:ListItem Value="4">Hollow and barrelish</asp:ListItem>
                </asp:DropDownList>
              <asp:RequiredFieldValidator ID="RequiredFieldValidator1" CssClass="text-danger" runat="server" ErrorMessage="Please choose wave type" ControlToValidate="wType"></asp:RequiredFieldValidator>
            </div>
            <label class="col-xs-11">What is your surfing style?</label>
            <div class="col-xs-11">
                <asp:CheckBox ID="CheckBox1" name="styleCB" runat="server" Text="Simple Cruising" /><br />
                <asp:CheckBox ID="CheckBox2" name="styleCB" runat="server" Text="On the Nose" />
                <br />
                <asp:CheckBox ID="CheckBox3" name="styleCB" runat="server" Text="Wide Carves" />
                <br />
                <asp:CheckBox ID="CheckBox4" name="styleCB" runat="server" Text="Fast Cuts & Snaps" />
                <br />
                <asp:CheckBox ID="CheckBox5" name="styleCB" runat="server" Text="Big Airs" />
                <br />
                <asp:CheckBox ID="CheckBox6" name="styleCB" runat="server" Text="Getting Barreled" />

            </div>
            <label class="col-xs-11">What do you wish to accomplish?</label>
            <div class="col-xs-11">
                <asp:DropDownList ID="trickSuitable" class="form-control" runat="server">
                    <asp:ListItem Value="0">--Select--</asp:ListItem>
                    <asp:ListItem Value="1">Learn to surf</asp:ListItem>
                    <asp:ListItem Value="2">Catch more Waves</asp:ListItem>
                    <asp:ListItem Value="3">Nail more tricks</asp:ListItem>
                    <asp:ListItem Value="4">Try something CRAZY!</asp:ListItem>
                </asp:DropDownList>
              <asp:RequiredFieldValidator ID="RequiredFieldValidator3" CssClass="text-danger" runat="server" ErrorMessage="Please select achievment " ControlToValidate="trickSuitable"></asp:RequiredFieldValidator>
            </div>
            <label class="col-xs-11">How skilled are you?</label>
            <div class="col-xs-11">
                <asp:DropDownList ID="skillReq" class="form-control" runat="server">
                    <asp:ListItem Value="0">--Select--</asp:ListItem>
                    <asp:ListItem Value="1">Wishing to start</asp:ListItem>
                    <asp:ListItem Value="2">Beginner</asp:ListItem>
                    <asp:ListItem Value="3">Intermediate</asp:ListItem>
                    <asp:ListItem Value="4">Advanced</asp:ListItem>
                    <asp:ListItem Value="4">Sponsored</asp:ListItem>
                </asp:DropDownList>
              <asp:RequiredFieldValidator ID="RequiredFieldValidator4" CssClass="text-danger" runat="server" ErrorMessage="Please choose your skill level " ControlToValidate="skillReq"></asp:RequiredFieldValidator>
            </div>

            <label class="col-xs-11">Enter your weight in kilo.</label>
            <div class="col-xs-11">
                <asp:TextBox ID="tbLweight" runat="server" class="form-control" placeholder="Your weight" CausesValidation="True" type="number" min="25" max="100"></asp:TextBox>
              <asp:RequiredFieldValidator ID="RequiredFieldValidator5" CssClass="text-danger" runat="server" ErrorMessage="Please type your weight " ControlToValidate="tbLweight"></asp:RequiredFieldValidator>
            </div>


            <div class="col-xs-11 space-vert">
                <asp:Button ID="btBoardMatch" runat="server" class="btn btn-success" Text="Match a board" OnClick="btBoardMatch_Click" />
            </div>
        </div>
        <div class="signUpImage">
            <div>
                By creating an account with<br />
                our store, you will be able to<br />
                move through the<br />
                checkout process faster,<br />
                view and track your orders<br />
                in your account and more.
            </div>
        </div>
    </div>
    <!-- Sign Up end -->

    protected void btnCart_Click(object sender, EventArgs e)
{
    Response.Redirect("~/Cart.aspx");
}

2 个答案:

答案 0 :(得分:2)

据我所知,你的按钮会触发验证。如果您不想按钮触发验证,请添加以下标记

CausesValidation="false"

这是你的购物车和登录在母版页中需要的样子

<asp:Button ID="btnCart" runat="server" OnClick="btnCart_Click"  CausesValidation="false" />

答案 1 :(得分:0)

您需要为每个RequiredFieldValidator要验证的元素添加验证组。

但请确保您没有为购物车和登录按钮指定验证组。

示例:

<!-- all elements below belong to group "order" -->
<asp:DropDownList ID="wSize" class="form-control" runat="server" validationgroup="order">
  <asp:ListItem Value="0">--Select--</asp:ListItem>
  <asp:ListItem Value="1">Knee to waist high</asp:ListItem>
  <asp:ListItem Value="2">Waist to chest high</asp:ListItem>
  <asp:ListItem Value="3">Chest to head high</asp:ListItem>
  <asp:ListItem Value="4">Overhead</asp:ListItem>
  <asp:ListItem Value="5">Double overhead plus</asp:ListItem>
</asp:DropDownList>    

<asp:RequiredFieldValidator ID="RequiredFieldValidatorwSize" CssClass="text-danger" runat="server" ErrorMessage="Please choose wave size" ControlToValidate="wSize" validationgroup="order"></asp:RequiredFieldValidator>

https://msdn.microsoft.com/en-us/library/ms227424.aspx