Handling Page Events

本文详细介绍了ASP.NET页面请求过程中的各个生命周期阶段及其顺序,并通过示例代码展示了关键事件的触发时机,帮助开发者理解何时执行何种操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

『本文系我自己看书做的笔记,有些是靠我弱智的英语自己看后做的笔记,难免有错误,日后也可会随时更改.大家发现错误可以指出,但少点嘲笑.各位看官请选择性收看.谢谢您的光临.』

 

当你请求一个ASP.NET的页面,一组事件按照一定的顺序被抛出,这个抛出事件的顺序我们称之为"页面的生命周期".
我们通常在Page Load事件中(Page_Load方法)初始化页面内的属性以及组件等,然而,这只是Page类中支持的事件的其中一个.

下面是当你请求一个ASP.NET的页面所派发出的事件以及其顺序:
1. PreInit
2. Init
3. InitComplete
4. PreLoad
5. Load
6. LoadComplete
7. PreRender
8. PreRenderComplete
9. SaveStateComplete
10. Unload
这么多啊,在不同的生命周期的阶段可访问不同的东西.
例如,ViewState直到派发完InitComplete事件后才被加载.

99%的情况下,我们不必处理所有的事件,通常我们常用的是两个:
1)Load:发生在所有的页面内组件所派发的事件之前;
2)PreRender:发生在所有的页面内组件所派发的事件之后;

下面的示例,演示说明了上面的情况:

 

事件处理的顺序很明显.

### LVGL 8 Page Component Documentation and Usage Examples In LVGL version 8, the `lv_page` object serves as a container that can scroll its children when they do not fit within the visible area. The primary purpose of this component is to provide an easy way to create pages with scrolling content. #### Creating a Basic Page Object To instantiate a basic page object in LVGL 8: ```c lv_obj_t * page = lv_page_create(lv_scr_act(), NULL); ``` This line creates a new page on the active screen (`lv_scr_act()`) without copying any existing styles or properties from another widget by passing `NULL`. #### Setting Up Scroll Bar Properties Scroll bars are essential features for indicating how much content has been scrolled through inside a page. In LVGL 8, configuring these settings involves using specific functions provided by the library: ```c // Enable horizontal scrollbar if needed. lv_page_set_scrlbar_mode(page, LV_SCRLBAR_MODE_AUTO); // Set padding around all sides of the child elements within the page. lv_page_set_scrollbar_mode(page, LV_SCROLLBAR_MODE_OFF); // Turn off scrollbars completely ``` The above configuration ensures that vertical scrollbars appear automatically based upon necessity while disabling horizontal ones entirely[^1]. #### Adding Content Inside Pages Adding objects into a page follows similar principles used elsewhere in LVGL but requires ensuring those items become part of the scroller rather than direct descendants of the page itself: ```c lv_obj_t * label; label = lv_label_create(page, NULL); lv_label_set_text(label, "Sample Text"); lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); ``` Here, creating a text label places it at the top-left corner relative to where the user starts viewing the contents of the page. Since labels get added directly under the page parentage hierarchy, they will move along during scrolls accordingly[^2]. #### Handling User Interaction Events Interacting with users often means responding appropriately once certain actions occur like clicking buttons placed inside pages. Event handling mechanisms allow developers to define custom behaviors triggered after detecting such events: ```c static void event_handler(lv_event_t event) { if(event == LV_EVENT_CLICKED){ printf("Page clicked\n"); } } lv_page_set_style(page,LV_PAGE_STYLE_BG,&style_bg); lv_obj_set_event_cb(page,event_handler); ``` Setting up an event callback function enables listening out specifically for click occurrences happening anywhere over the entire surface area covered by our defined page instance here[^3]. --related questions-- 1. How does one customize the appearance of a page's background color? 2. What methods exist for controlling the visibility state of scrollbars associated with pages? 3. Can animations be applied smoothly onto transitions between different positions reached via scrolling operations performed against pages? 4. Is there support available within LVGL 8 for implementing pull-to-refresh functionality tied closely alongside pages containing dynamic data sources?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值