1.建立了一个独立网页页面(resultPage),并将主网页上的按钮指向这个独立页面,设置按钮的属性:PostBackUrl属性,将其指定到这个独立的页面上。并编辑这个页面载入事件。
public partial class ResultPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { try { DropDownList dropDownListEvents = (DropDownList)PreviousPage.FindControl("dropDownListEvents"); string selectedEvent = dropDownListEvents.SelectedValue; string fistName = ((TextBox)PreviousPage.FindControl("textFirstName")).Text; string lastName = ((TextBox)PreviousPage.FindControl("textLastName")).Text; string email = ((TextBox)PreviousPage.FindControl("textEmail")).Text; labelResult.Text = String.Format("{0} {1} selected the event {2}", fistName, lastName, selectedEvent); } catch { labelResult.Text = "The originating page must contain" + "textFirstName, textLastName, textEmail controls"; } } }
学习了a,得到PreviousPage的值 b, FindControl的使用。c,try{} catch{}
2.在ASP.net项目上建立新类
public class RegistrationInfo { public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string SelectedEvent { get; set; }
}
随后在首个页面上的给Registration类添加公共属性
public RegistrationInfo RegistrationInfo { get { return new RegistrationInfo { FirstName = textFirstName.Text, //这个地方不是分号“;”一定要注意。 LastName = textFirstName.Text, Email = textEmail.Text, }; } }
注意get内部代码的特点。 由于我是新手,对这个不是很了解,所以,在编写中将代码中的逗号“,”一直写为分号“;” 结果怎么都不对,而且一直报错。我不知道怎么回事,但是发现
return new RegistrationInfo{}后面还有分号“;” 才注意到里面每个语句后面是逗号“,”; 而且很长时间才发现咋回事呢。所以,要注意。