Chinaunix首页 | 论坛 | 博客
  • 博客访问: 511978
  • 博文数量: 88
  • 博客积分: 2256
  • 博客等级: 大尉
  • 技术积分: 921
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-08 23:20
个人简介

积硅步,行千里

文章分类

全部博文(88)

文章存档

2019年(5)

2018年(1)

2016年(15)

2015年(23)

2013年(3)

2012年(6)

2011年(3)

2010年(22)

2009年(10)

我的朋友

分类: C#/.net

2016-05-23 10:47:20

第1种回送方式:同页面回送测试数据
新建几个Label和一个Button  在同一页面旋转一个隐藏Label用于显示传递数据显示。OnButtonClick代码如下:
同页面显示数据:
  1. protected void buttonSubmit_Click(object sender, EventArgs e)
  2.         {
  3.             string selectedEvent = dropDownListEvents.SelectedValue;
  4.             string txtFirstName = textFirstName.Text;
  5.             string txtLastName = textLastName.Text;
  6.             string txtEmail = textEmail.Text;
  7.             labelResult.Text = string.Format("{0} {1} selected {2},the Email Address is {3}",txtFirstName,txtLastName,selectedEvent,txtEmail);
  8.         }
第2种回送方式:第二页面显示测试数据(非调用类方法传递数据)
1.关键在提交按钮中设置:postbackurl地址设置为新结果而Resultpage.aspx;
2.在resultpage.aspx页面中page_load中加入此代码:

  1. try
  2.                     {
  3.                         DropDownList dropDownListEvents = (DropDownList)PreviousPage.FindControl("dropDownListEvents");
  4.                         string selectedEvent = dropDownListEvents.SelectedValue;
  5.                         string firstName = ((TextBox)PreviousPage.FindControl("textFirstName")).Text;
  6.                         string lastName = ((TextBox)PreviousPage.FindControl("textLastName")).Text;
  7.                         string email = ((TextBox)PreviousPage.FindControl("textEmail")).Text;
  8.                         labelResult.Text = String.Format("{0} {1} selected the event {2}",firstName, lastName, selectedEvent);
  9.                      }
  10.                 catch
  11.                     {
  12.                         labelResult.Text = "The originating page must contain " + "textFirstName, textLastName, textEmail controls";
  13.                     }

第3种回送方式:(使用公共类方法调用传递参数数据)
1.新建一个公共类方法(RegistrationInfo类):

  1. public class RegistrationInfo
  2.     {
  3.         public string FirstName { get; set; }
  4.         public string LastName { get; set; }
  5.         public string Email { get; set; }
  6.         public string SelectedEvent { get; set; }
  7.     }
2.在Registration.aspx中调用这个公共类并赋值:

  1. public RegistrationInfo RegistrationInfo
  2.         {
  3.             get
  4.             {
  5.                 return new RegistrationInfo
  6.                 {
  7.                     FirstName = textFirstName.Text,
  8.                     LastName = textLastName.Text,
  9.                     Email = textEmail.Text,
  10.                     SelectedEvent = dropDownListEvents.SelectedValue
  11.                 };
  12.             }
  13.         }
3.在结果页resultpage.aspx中显示出来,使用previouspage获取前面页面数据
  1. protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             try
  4.             {
  5.                 if (!PreviousPage.IsValid)
  6.                 {
  7.                     labelResult.Text = "Error in previous page!";
  8.                     return;
  9.                 }
  10.                 RegistrationInfo ri = PreviousPage.RegistrationInfo;
  11.                 labelResult.Text = String.Format("{0} {1} selected the event {2} ,Email Address is {3}",ri.FirstName, ri.LastName, ri.SelectedEvent,ri.Email);
  12.             }
  13.             catch
  14.             {
  15.                 labelResult.Text = "The originating page must contain " + "textFirstName, textLastName, textEmail controls";
  16.             }
  17. }




阅读(1109) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~