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">Event</td> 4 <td> 5 <asp:DropDownList ID="ddl_events" runat="server"> 6 <asp:ListItem>a</asp:ListItem> 7 <asp:ListItem Selected="True">b</asp:ListItem> 8 <asp:ListItem>c</asp:ListItem> 9 </asp:DropDownList> 10 </td> 11 </tr> 12 <tr> 13 <td class="auto-style2">First Name</td> 14 <td> 15 <asp:TextBox ID="firstName" runat="server"></asp:TextBox> 16 </td> 17 </tr> 18 <tr> 19 <td class="auto-style2">Last Name</td> 20 <td> 21 <asp:TextBox ID="lastName" runat="server"></asp:TextBox> 22 </td> 23 </tr> 24 <tr> 25 <td class="auto-style2">Email</td> 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 + "<br/>" + "firstName:" + firstName + "<br/>" + "lastName:" + lastName + "<br/>" + "email:" + email + "<br/>"; } 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 + "<br/>" 7 + "firstName:" + ri.firstName + "<br/>" 8 + "lastName:" + ri.lastName + "<br/>" 9 + "email:" + ri.email + "<br/>"; 10 } 11 catch{ 12 lbl_message.Text = "Request Fail"; 13 }