ASP.NET基础

ASP.NET基础

1.如何理解viewstate?
参考What is viewstate in asp.net - Part 3

Web应用是基于HTTP,HTTP协议是无状态协议,它并不保存请求的状态,所以可以使用viewstate 来保存不同请求间的状态。

ClicksCount = (int)ViewState["Clicks"] + 1;

ViewState数据序列化为base64编码的字符串,保存在隐藏域__ViewState

ASP.NET的服务器控件会保存状态,而HTML控件则不会。HTML控件可以通过添加runat="server"变为ASP.NET服务器控件

2.web应用生命周期中的事件
参考Events in the life cycle of a web application - Part 4

如果想要在多个Web表单中提供数据,在ASP.NET中有如下的方式:
1. Query Strings
2. Cookies
3. Session State
4. Application State

注意Session State 与Application State、ViewState的区别,可参考Difference between ViewState, Session State and Application State in asp.net - Part 5

页面的生命周期ASP.NET Page Life Cycle Events - Part 6

当一个webform的请求到来时,事件执行的顺序如下:
1. Web Application creates an instance of the requested webform.
2. Processes the events of the webform.
3. Generates the HTML, and sends the HTML back to the requested client.
4. The webform gets destroyed and removed from the memory.

3.服务器控件的事件
参考ASP.NET Server control events - Part 7

控件的事件类型可分为3类:

1.Postback事件-提交webpage,直接到服务器处理。如button的click事件就是Postback事件
2.Cached事件-这些事件保存在page的viewstate中待处理,直到一个postback事件发生。例如,TextBoxTextChanged事件,DropDownListSelectedIndexChanged 事件。Cached事件可被转化为Postback事件,通过设置AutoPostBacktrue
3.Validation事件-在page被post back到server之前,在客户端发生

4.对IsPostBack的理解
参考IsPostBack in asp.net - Part 8

IsPostBack is a Page level property, that can be used to determine whether the page is being loaded in response to a client postback, or if it is being loaded and accessed for the first time.

5.Page的生命周期

参考ASP.NET Page Life Cycle Events - Part 6

  • Page_PreInit在页面初始化事件之前发生。在此阶段,设置IsPostBackIsCallbackIsCrossPagePostBack 属性。这个事件中可以动态的设置master page和web应用的主题。PreInit在使用动态控件时被广泛使用。
  • Page_Init使用此事件来读取或初始化控件属性。
  • Page_InitComplete
  • Page_PreLoad
  • Page_Load
  • Page_LoadComplete
  • Page_PreRender
  • Page_PreRenderComplete
  • Page_Unload

ASP.NET控件

1.TextBox控件
参考ASP.NET TextBox Control - Part 10

属性:

  • AutoPostBack- By default, the TextChanged event of a TextBox control is cached in the viewstate, and is executed when the webform is submitted thru a postback by clicking the button control. If you want to change this behaviour, and post the webform immediately when the Text is changed, set AutoPostBack to true. Setting this property to true, will convert the cached event into a postback event.

方法

  • Focus()

事件:

  • TextChanged

2.RadioButton控件
属性

  • Checked表示是否选中
  • GroupName默认的,每个Radio不是互斥的。如果想要互斥,对
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值