2016-04-08 89 views
0

所以我們正在構建一個應用程序,人們每年每個裏面放入一個數據庫提交在線表單彩票的開獎保留我們再使用運行彩票洗牌和其他管理任務。但是我希望人們被重定向到彩票表格的收據上,顯示他們在提交表格時所輸入的選項和其他信息。什麼是最好的方法來做到這一點?最好的辦法

我看了看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(); 
      } 
     } 
    } 
} 
+0

你應該真的把這些信息保存到你的會話中。然後,您可以從應用程序中的任何其他頁面訪問它。 –

+0

謝謝傑森,你是對的。我對asp很新,並不確定哪種方法對於這個應用程序最有意義 – HiCntry

回答

0

有兩件事情,你會給出一些更多的經驗,這種情況理解。

  1. 創建一個班級並在其中存儲您的信息。
  2. 使用「會話」來保存數據當前人。該會話被使用以便當訪問者在頁面之間移動時數據可用。只需Google「ASP.net會話」瞭解更多詳情。