【问题标题】:best way to create a form submission receipt in asp.net在 asp.net 中创建表单提交收据的最佳方法
【发布时间】:2016-04-10 22:45:39
【问题描述】:

因此,我们正在构建一个应用程序,人们可以在该应用程序中在线提交每年预订彩票的彩票表格,然后将这些表格放入数据库中,然后用于运行彩票随机播放和其他管理任务。但我希望人们被重定向到彩票表格的收据,其中显示了他们在提交表格时输入的选项和其他信息。最好的方法是什么?

我查看了 MSDN 文章,我认为查询字符串方法太麻烦了,因为该表单有 15 个以上的控件,包括一个可能非常大的开放式选择字段。我应该使用 POST 方法吗?我们不会在收据上包含任何付款信息。下面是表单的原始代码。

.aspx 页面

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="lottoForm.aspx.cs" Inherits="lottoForm" %>
<%-- reference site http://www.tinymce.com/wiki.php --%>


<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
    <h1>2016 - 2017 Reservations Lottery Form</h1>
    <asp:Label ID="dbErrorMessage" ForeColor="Red" runat="server" />

        <fieldset id="contactInfo">
        <legend>Contact Information</legend>
        <ol>
        <li><label for="First">First Name:<em>*</em><asp:TextBox id="first" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></label></li>  
        <li><label for="Last">Last Name:<em>*</em><asp:TextBox id="last" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></label></li>
        <li><label for="Addr1">Address:<em>*</em><asp:TextBox id="Addr1" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></label></li>
        <li><label for="C">City:<em>*</em><asp:TextBox id="C" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></label></li>
        <li><label for="S">State:<em>*</em><asp:TextBox id="S" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></label></li> 
        <li><label for="Z">Zipcode:<em>*</em><asp:TextBox id="Z" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></label></li>
        <li><label for="dayphone">Daytime Phone Number:<em>*</em><asp:TextBox id="dayphone" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></label></li> 
        <li><label for="eveningphone">Evening Phone Number:<em>*</em><asp:TextBox id="eveningphone" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox> </label></li>
        <li><label for="email">Email <span class="formcaption">(for email confirmation, not for distribution)</span>:<em>*</em><asp:TextBox id="email" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></label></li>
        </ol>
        </fieldset>
        <fieldset id="tripCredit">
        <legend>Trip Payment Information</legend>
        <ol>
        <li><label for="tripCC">Visa/MC/Amex <span class="formcaption">(for trip purchase)</span>:<em>*</em></label> <asp:TextBox id="tripCC" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></li>
        <li><label for="tripCCexpiration">Expiration Date:<em>*</em></label> <asp:TextBox id="tripCCexpiration" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></li>
        <li><label for="tripCVV">CVV:<em>*</em></label> <asp:TextBox id="tripCVV" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></li>
        <li><label for="tripCCname">Name as it appears on card:<em>*</em></label> <asp:TextBox id="tripCCname" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></li>
        </ol>
        </fieldset>
        <fieldset id="memberCredit">
        <legend>Membership Payment Information <span class="formcaption">(if different than trip payment)</span></legend>
        <ol>
        <li><label for="memberCC">Visa/MC/Amex <span class="formcaption">(for membership)</span>:</label><asp:TextBox id="memberCC" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></li>
        <li><label for="memberCCexpiration">Expiration Date:</label> <asp:TextBox id="memberCCexpiration" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></li>
        <li><label for="memberCVV">CVV:</label> <asp:TextBox id="memberCVV" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></li>
        <li><label for="memberCCname">Name as it appears on card:<em>*</em></label> <asp:TextBox id="memberCCname" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox></li>
        </ol>
        </fieldset>
        <fieldset style="clear:both;">
        <legend>Terms and Conditions</legend>
        <h4>Please read and initial the following items. Reservation requests must have these items initialed or they will not be processed.</h4>
        <ul>
            <li>I understand that 10th Mountain will book me into the first available trip from my listed choices when my form is drawn in the lottery. I understand that this booking is subject to the REGULAR CANCELLATION POLICIES and I agree to allow 10th Mountain to CHARGE THIS TRIP AND RELATED FEES IN FULL TO MY CREDIT CARD.<br><label class="subheading" for="CCcharge"><input type="checkbox" name="CCcharge" value="yes">Check to confirm</label></li>
            <li>I understand that if I reserve a trip at Fowler/Hilliard, Jackal, Janet's or Shrine Mountain Inn (Jay's, Chuck's, or Walter's) from Friday, November 25, 2016, through Saturday, April 22, 2017 I will be required to pay the Vail Pass Winter Recreation Fee to 10th Mountain at the time of booking. These fees may be increased without notice for the 2016-2017 season.<br><label class="subheading" for="VPFee"><input type="checkbox" name="VPFee" value="yes">Check to confirm</label></li>
            <li>I understand that rates for huts not owned by 10th Mountain may increase and that I will not be notified of price increases before I am charged. Any price changes will be posted on the website, www.huts.org.<br><label class="subheading" for="HutFee"><input type="checkbox" name="HutFee" value="yes">Check to confirm</label></li>
            <li>I understand that if changes or cancellations to trips booked through this lottery are made 30 days in advance, an 80% hut credit for a future trip will be issued and that NO REFUNDS will be given. I understand that changes or cancellations made less than 30 days prior to my trip date will result in forfeiture of my payment and that NO REFUNDS OR CREDITS will be issued.<br><label class="subheading" for="cancellation"><input type="checkbox" name="cancellation" value="yes">Check to confirm</label></li>
            <li>I have researched the trips that I have requested and determined that my group has the skills necessary to safely attempt these itineraries.<br><label class="subheading" for="tripResearch"><input type="checkbox" name="tripResearch" value="yes">Check to confirm</label></li>
            <li>I understand that I must be a 10th Mountain, SHA or Grand Huts Association member in order to participate in this lottery. If I am not currently a member, or if my annual membership is up for renewal in March or April, I agree to allow 10th Mountain TO CHARGE THE MEMBERSHIP FEE TO MY CREDIT CARD BEFORE THE LOTTERY DRAWING.<br><label class="subheading" for="membership"><input type="checkbox" name="member" value="yes">Check to confirm</label></li>
        </ul>
        </fieldset>
        <fieldset id="members">
            <legend>Membership Renewal</legend>
            <h4>If you are not a member, or if your membership is up for renewal in March or April, at which level would you like to join or renew?</h4>
            <label for="membership" class="error">Please select your membership renewal staus</label>
            <asp:RadioButtonList ID="membership" runat="server" RepeatDirection="Vertical">
                <asp:ListItem> I cannot remember. Please renew my 10th Mountain membership at my current level.</asp:ListItem>
                <asp:ListItem> Not applicable, my 10th Mountain membership is current.</asp:ListItem>
                <asp:ListItem> 10th Mountain $35 Annual Membership (Reserve 1 trip in the lottery and up to 2 additional trips between April 1 and May 31. You will also receive a gift and newsletters.)</asp:ListItem>
                <asp:ListItem> 10th Mountain $100 Annual Membership (Reserve 1 trip in the lottery and an unlimited number of additional trips between April 1 and May 31. You will also receive a gift, newsletters, and notecards.)</asp:ListItem>
                <asp:ListItem> 10th Mountain $1000 Lifetime Membership (Leader benefits plus a cap, T-shirt, and guidebook.)</asp:ListItem>
                <asp:ListItem> I am a Grand Huts Association member. Please renew my membership with GHA if needed or sign me up for the following: $25/person</asp:ListItem>
                </asp:RadioButtonList>
            <p>I am a Summit Huts Association member. Please renew my membership with SHA if needed or sign me up for the following: $25/person $35/family.<br>
            <asp:RadioButtonList ID="shaMembership" runat="server" RepeatDirection="Vertical">
                    <asp:ListItem> Single - $25</asp:ListItem>
                    <asp:ListItem> Family - $35</asp:ListItem>
                </asp:RadioButtonList>
            </p>
        </fieldset>
        <fieldset>
        <legend>Hut Credit Information</legend>
        <p>Do you have a hut credit(s) or gift certificate(s) on file that you would like to apply toward this trip?</p>
        <asp:RadioButtonList ID="hutCredit" runat="server" RepeatDirection="Vertical">
        <asp:ListItem>Yes</asp:ListItem>
        <asp:ListItem>No</asp:ListItem>
            </asp:RadioButtonList>
        <p>If yes what name was it issued under? <asp:TextBox id="creditname" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox><br>
        <span class="formcaption">(Please note that if your credit has expired, your credit card will be charged in full for your trip)</span></p>
        </fieldset>
        <fieldset>
        <legend>Hut Reservation Lottery Choices</legend>
        <label for="GroupName" class="subheading">Group Name <span class="formcaption">(LEAVE BLANK unless you have read and understand the group entry process. <span id="sprytrigger1" class="classiclink">See Instructions #8</span>)</span>:</label> <asp:TextBox id="GroupName" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox>
        <div class="tooltipContent" id="sprytooltip1">If you have a group of members who will each submit a request form and your group would like to book only ONE trip, please follow the directions below carefully:<br>
        <ul>    
        <li>Assign your group a unique name and enter this name on the top of the form on the Group Name line.</li> 
        <li>Be sure that each of the group's participants uses the same group name, and includes the name on the top of their form.</li> 
        <li>Make sure that the members of your group each submit IDENTICAL lists of choices.</li> 
        </ul>           
        You are not a group if you only have one person entering. Once a member of the group receives a trip, all of the other lottery forms with the same group name will be discarded. The group will receive only one trip.</div>
        <p>We encourage you to make as many choices as possible. There is no limit on the text area for your choices. If you find it more convenient you can attach a MS Word or Excel file with your choices using the "File upload" option below. Please be sure you are looking at the correct calendar for the year 2016-2017.</p>
        <p>File to upload: <input type="file" name="first_file" /></p>
        <label for="LotteryChoices" class="subheading">Lottery Choices:</label> <asp:TextBox ID="LotteryChoices" TextMode="SingleLine" Columns="30" runat="server"></asp:TextBox>
        </fieldset>

        <p><asp:Button id="submitButton" runat="server" Text="Submit Lottery Form" OnClick="submitButton_Click" /></p>

</asp:Content>

代码隐藏

public partial class lottoForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void submitButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            SqlConnection conn;
            SqlCommand comm;
            string connectionString = ConfigurationManager.ConnectionStrings["10thLottoApp"].ConnectionString;
            conn = new SqlConnection(connectionString);
            comm = new SqlCommand("INSERT INTO Lotto (First, Last, Addr1, C, S, Z, dayphone, eveningphone, email, tripCC, tripCCexpiration, tripCVV, tripCCname, memberCC, memberCCexpiration, memberCVV, memberCCname, membership, shaMembership, hutCredit, creditName, GroupName, LotteryChoices) Values(@First, @Last, @Addr1, @C, @S, @Z, @dayphone, @eveningphone, @email, @tripCC, @tripCCexpiration, @tripCVV, @tripCCname, @memberCC, @memberCCexpiration, @memberCVV, @memberCCname, @membership, @shaMembership, @hutCredit, @creditName, @GroupName, @LotteryChoices)", conn);
            comm.Parameters.Add("@First", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@First"].Value = first.Text;
            comm.Parameters.Add("@Last", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@Last"].Value = last.Text;
            comm.Parameters.Add("@Addr1", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@Addr1"].Value = Addr1.Text;
            comm.Parameters.Add("@C", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@C"].Value = C.Text;
            comm.Parameters.Add("@S", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@S"].Value = S.Text;
            comm.Parameters.Add("@Z", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@Z"].Value = Z.Text;
            comm.Parameters.Add("@dayphone", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@dayphone"].Value = dayphone.Text;
            comm.Parameters.Add("@eveningphone", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@eveningphone"].Value = eveningphone.Text;
            comm.Parameters.Add("@email", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@email"].Value = email.Text;
            comm.Parameters.Add("@tripCC", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@tripCC"].Value = tripCC.Text;
            comm.Parameters.Add("@tripCCexpiration", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@tripCCexpiration"].Value = tripCCexpiration.Text;
            comm.Parameters.Add("@tripCVV", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@tripCVV"].Value = tripCVV.Text;
            comm.Parameters.Add("@tripCCname", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@tripCCname"].Value = tripCCname.Text;
            comm.Parameters.Add("@memberCC", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@memberCC"].Value = memberCC.Text;
            comm.Parameters.Add("@memberCCexpiration", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@memberCCexpiration"].Value = memberCCexpiration.Text;
            comm.Parameters.Add("@memberCVV", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@memberCVV"].Value = memberCVV.Text;
            comm.Parameters.Add("@memberCCname", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@memberCCname"].Value = memberCCname.Text;
            comm.Parameters.Add("@membership", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@membership"].Value = membership.Text;
            comm.Parameters.Add("@shaMembership", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@shaMembership"].Value = shaMembership.Text;
            comm.Parameters.Add("@hutCredit", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@hutCredit"].Value = hutCredit.Text;
            comm.Parameters.Add("@creditname", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@creditname"].Value = creditname.Text;
            comm.Parameters.Add("@GroupName", System.Data.SqlDbType.NVarChar, 50);
            comm.Parameters["@GroupName"].Value = GroupName.Text;
            comm.Parameters.Add("@LotteryChoices", System.Data.SqlDbType.NVarChar, -1);
            comm.Parameters["@LotteryChoices"].Value = LotteryChoices.Text;


            try
            {
                conn.Open();
                comm.ExecuteNonQuery();
                Response.Redirect("lottoReceipt.aspx");
            }
            catch
            {
                dbErrorMessage.Text = "There was an error submitting your lottery form.";
            }
            finally
            {
                conn.Close();
            }
        }
    }
}

【问题讨论】:

  • 您确实应该将此信息保存到您的会话中。然后您可以从应用程序中的任何其他页面访问它。
  • 谢谢杰森,你是对的。我对 asp 很陌生,不确定哪种方法最适合这个应用程序

标签: c# asp.net forms


【解决方案1】:

在这种情况下,如果有更多经验,您会理解两件事。

  1. 创建一个类并将您的信息存储在其中。
  2. 使用“会话”保存当前人员的数据。使用会话以便当访问者从一个页面移动到另一个页面时数据可用。只需谷歌“ASP.net Sessions”了解更多详情。

【讨论】:

    猜你喜欢
    • 2011-03-20
    • 1970-01-01
    • 2017-11-03
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    相关资源
    最近更新 更多