day6.1

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{}后面还有分号“;” 才注意到里面每个语句后面是逗号“,”; 而且很长时间才发现咋回事呢。所以,要注意。

转载于:https://www.cnblogs.com/52iiiii/archive/2012/02/25/2367592.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值