0

这是我在 Visual Studio 中的 Web 表单。用户单击“提交”按钮后,将显示另一个视图,感谢他们填写表单,但该按钮仍显示在页面上,并带有感谢消息。点击后如何让它消失?

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HelloWebForm.aspx.cs" Inherits="WebApplication1.HelloWebForm" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="width: 37px">
        <asp:Panel ID="PanelNameForm" runat="server" Width="502px">
            <asp:Label ID="LabelFirstName" runat="server" Text="First Name"></asp:Label>
            <asp:TextBox ID="TextBoxFirstName" runat="server"></asp:TextBox>
            <asp:Label ID="LabelLastName" runat="server" Text="Last Name"></asp:Label>
            <asp:TextBox ID="TextBoxLastName" runat="server"></asp:TextBox> <br />
            <asp:Label ID="LabelAddr1" runat="server" Text="Address"></asp:Label>
            <asp:TextBox ID="TextBoxAddr1" runat="server"></asp:TextBox>
            <asp:Label ID="LabelAddr2" runat="server" Text="Address"></asp:Label>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
            City<asp:TextBox ID="TextBoxAddr2" runat="server"></asp:TextBox>
            State<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            Zip<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            <br />
            Phone Number<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
            email<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
            Age<asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem Value="1">0-17</asp:ListItem>
                <asp:ListItem Value="2">18-21</asp:ListItem>
                <asp:ListItem Value="3">22-25</asp:ListItem>
                <asp:ListItem Value="4">26-35</asp:ListItem>
                <asp:ListItem Value="5">36+</asp:ListItem>
            </asp:DropDownList>
            <asp:Panel ID="Panel1" runat="server" Width="407px">
                Gender<asp:RadioButtonList ID="RadioButtonList1" runat="server">
                    <asp:ListItem Value="Male">Male</asp:ListItem>
                    <asp:ListItem Value="Female">Female</asp:ListItem>
                </asp:RadioButtonList>
                Favorite Cheese<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
                <br />
                How often do you eat cheese? (Check one)<asp:CheckBoxList ID="CheckBoxList1" runat="server" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
                    <asp:ListItem>Every Day</asp:ListItem>
                    <asp:ListItem>Every Other Day</asp:ListItem>
                    <asp:ListItem>Once A Week</asp:ListItem>
                    <asp:ListItem>I Don&#39;t Like Cheese</asp:ListItem>
                </asp:CheckBoxList>
                Cheese Texture Preferences (Check All That Apply)<asp:CheckBoxList ID="CheckBoxList2" runat="server">
                    <asp:ListItem Value="1">Hard</asp:ListItem>
                    <asp:ListItem Value="2">Semi-hard</asp:ListItem>
                    <asp:ListItem Value="3">Semi-soft</asp:ListItem>
                    <asp:ListItem Value="4">Soft</asp:ListItem>
                    <asp:ListItem Value="5">Crumbly</asp:ListItem>
                </asp:CheckBoxList>
                Milk Type Preferences (Check All That Apply)<asp:CheckBoxList ID="CheckBoxList3" runat="server">
                    <asp:ListItem>Buffalo</asp:ListItem>
                    <asp:ListItem>Cow</asp:ListItem>
                    <asp:ListItem>Goat</asp:ListItem>
                    <asp:ListItem>Vegetarian</asp:ListItem>
                </asp:CheckBoxList>
            </asp:Panel>
        </asp:Panel>
        <asp:Panel ID="PanelThankYou" runat="server" Width="442px">
            Thank you for taking the survey, <asp:Label ID="LabelThankYouName" runat="server" Text=""></asp:Label>
        </asp:Panel>
    </div>
        <asp:Button ID="Button" runat="server" Text="Submit" OnClick="Button_Click" />
    </form>
</body>
</html>
4

3 回答 3

3

您可以将按钮添加到 PanelNameForm,然后单击它就可以隐藏整个面板。在 Onclick_button 事件上添加。

PanelThankYou.Visible = true
PanelNameForm.Visible = false
于 2013-09-21T03:11:31.450 回答
1

Ordinary a normal practice is to redirect to a separate "Thank You" page upon form submit.

In your case you can simple add

Button.Visible = False

Into Button's click event. (btw, you may want to change ID of the button to something different from the reserved word).

于 2013-09-21T03:04:59.320 回答
0

set autopostback=true in your design code,

then in your code behind class file check for ispagepostback property if its true submit say thanks n load new page or hide the thank you message..

于 2013-09-21T03:05:26.577 回答