ASP.Net返送.データ送信別ページ

19004 ワード

SetPage.aspx
GetPage.aspx
 
1、SetPage.aspx
主:button属性はPostBackUrl="~/Upload/GetPage.aspx"に設定
 1 <table cellpadding="0" cellspacing="0" class="auto-style1">
 2                 <tr>
 3                     <td class="auto-style2">Eventtd>
 4                     <td>
 5                         <asp:DropDownList ID="ddl_events" runat="server">
 6                             <asp:ListItem>aasp:ListItem>
 7                             <asp:ListItem Selected="True">basp:ListItem>
 8                             <asp:ListItem>casp:ListItem>
 9                         asp:DropDownList>
10                     td>
11                 tr>
12                 <tr>
13                     <td class="auto-style2">First Nametd>
14                     <td>
15                         <asp:TextBox ID="firstName" runat="server">asp:TextBox>
16                     td>
17                 tr>
18                 <tr>
19                     <td class="auto-style2">Last Nametd>
20                     <td>
21                         <asp:TextBox ID="lastName" runat="server">asp:TextBox>
22                     td>
23                 tr>
24                 <tr>
25                     <td class="auto-style2">Emailtd>
26                     <td>
27                         <asp:TextBox ID="email" runat="server">asp:TextBox>
28                     td>
29                 tr>
30                 <tr>
31                     <td class="auto-style2"> td>
32                     <td>
33                         <asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="~/Upload/GetPage.aspx" />
34                     td>
35                 tr>
36             table>

 
GetPage.aspx弱受信データ
if (!IsPostBack)
            {
                try
                {
                    //1.
                    DropDownList ddl_events = (DropDownList)PreviousPage.FindControl("ddl_events");

                    string events = ddl_events.SelectedValue;
                    string firstName = ((TextBox)PreviousPage.FindControl("firstName")).Text;
                    string lastName = ((TextBox)PreviousPage.FindControl("lastName")).Text;
                    string email = ((TextBox)PreviousPage.FindControl("email")).Text;

                    this.lbl_message.Text = "events:" + events + "
" + "firstName:" + firstName + "
" + "lastName:" + lastName + "
" + "email:" + email + "
"; } catch{ lbl_message.Text = "Request Fail"; } }

2、強受信データ:
2.1クラスの作成
public class RegistrationInfo
    {
        public string events { get; set; }
        public string firstName { get; set; }
        public string lastName { get; set; }
        public string email { get; set; }
    }

2.2 SetPage.aspx共通属性RegistrationInfoの追加
 1 public RegistrationInfo RegistrationInfo
 2         {
 3             get {
 4                 return new RegistrationInfo
 5                 {
 6                     events = this.ddl_events.SelectedValue,
 7                     firstName = this.firstName.Text,
 8                     lastName = lastName.Text,
 9                     email = email.Text
10                 };
11             }
12         }

2.3 GetPage.aspx呼び出し
 1 try
 2                 {
 3                     //2.
 4                     RegistrationInfo ri = PreviousPage.RegistrationInfo;
 5 
 6                     this.lbl_message.Text = "events2:" + ri.events + "
" 7 + "firstName:" + ri.firstName + "
" 8 + "lastName:" + ri.lastName + "
" 9 + "email:" + ri.email + "
"; 10 } 11 catch{ 12 lbl_message.Text = "Request Fail"; 13 }