《Programming ASP.NET》学习笔记(MultiView和View控件)

MultiView和View控件

块是页面中某区域的内容,ASP.NET提供了View控件对块进行管理。
每个块对应一个View控件,所有View对象包含在MultiView对象中。
MultiView中每次只显示一个View对象,这个对象称为活动视图。

View和MultiView控件是从System.Web.UI.Control类继承。

MultiView控件有一个类型为ViewCollection的只读属性View。
使用该属性可获得包含在MultiView中的View对象集合。
与所有的.NET集合一样,该集合中的元素被编入索引。
MultiView控件包含ActiveViewIndex属性,该属性可获取或设置以0开始的,当前活动视图的索引。如果没有视图是活动的,那么ActiveViewIndex为默认值-1。

MultiView控件的4个CommandName字段。为按钮的CommandName属性赋值,能够实现视图导航。
字段    默认命令名  说明
NextViewCommandName  NextView
导航到具有更高ActiveViewIndex值的视图。如果当前位于最后的视图,则设置ActiveViewIndex为-1,不显示任何视图

PreviousViewCommandName  PrevView
导航到低于ActiveViewIndex值的视图。如果当前位于第一个视图,则设置ActiveViewIndex为-1,不显示任何视图

SwitchViewByIDCommandName SwitchViewByID
导航到指定ID的视图,可以使用CommandArgument指定ID值

SwitchViewByIndexCommandName SwitchViewByIndex
导航到指定索引的视图,使用CommandArgument属性指定索引

例如,将Button、ImageButton或LinkButton控件的CommandName属性设置为NextView,单击这些按钮后将自动导航到下一个视图。

通过调用MultiView控件的SetActiveView或GetActiveView方法可以设置或获取活动视图。SetActiveView使用View对象作为参数,而GetActiveView则返回一个View对象。

提示:记住,即使视图不可见,它所包括的所有控件对于应用程序和服务器端也都是可用的。不仅在代码中可用,而且还具有自己的视图状态,并作为页面的控件集合的一部分。

每次视图发生变化时,页面都会被提交到服务器,同时MultiView控件和View控件将触发多个事件。
ActiveViewChanged 事件 活动视图发生变化时,MultiView控件触发
Activate 事件 活动视图发生变化时,新的活动视图触发
Deactivate 事件 活动视图发生变化时,原活动视图触发

所有的事件都包含一个EventArgs类型的参数。该参数只是一个占位符,它没有提供与事件相关的附加信息。对事件源的引用将传递给事件处理程序。

View控件包含一个Boolean类型的Visible属性
设置该属性可以控制特定View对象的可见性,或以编程方式确定哪一个View是可见的。

MultiView和View控件都没有样式属性
对于View控件而言,如果要使用样式属性,则必须将样式应用到每一个它包含的控件中。
或者在View控件中嵌入一个Panel控件,并设置Panel的样式属性。 

Programming ASP.NET By Dan Hurwitz, Jesse Liberty October 2005 ASP.NET, successor to Microsoft's Active Server Pages (ASP), is so complete and flexible that a web developer's main difficulty may lie simply in weaving the pieces together for maximum efficiency. The new edition of Programming ASP.NET shows developers how to do just that. Updated for Version 1.1 of the NET framework and Visual Studio .NET 2003, the second edition of this bestselling .NET title will show you how to create dynamic, data-driven web sites and services using both C# and Visual Basic .NET. In Programming ASP.NET, Second Edition authors Jesse Liberty and Dan Hurwitz cover everything you need to know to be effective with ASP.NET. The book includes a comprehensive tutorial on Web Forms, which, in conjunction with Visual Studio .NET 2003, allow you to apply Rapid Application Development techniques (including drag-and-drop control placement) to web development. Programming ASP.NET includes extensive coverage of each type of server control, including Web server controls, HTML server controls, and custom controls. New material covers creating ASP.NET pages for mobile devices. Since most web applications and web services involve retrieving data and returning it to a client browser, Programming ASP.NET Second Edition also offers extensive coverage of data access issues. These include topics such as using ASP.NET's list-bound controls; accessing data using the ADO.NET object model, and updating data with or without transaction support. Programming ASP.NET also discusses such advanced topics as: Caching and performance Security Configuration and deployment If you're already familiar with Active Server Pages technology, you'll appreciate the in-depth focus and straightforward, easy-to-read approach for developing web pages and web services. Succinct, direct, and loaded with examples, Programming ASP.NET, Second Edition will help users at every level master ASP.NET without getting bogged down in the complexity of its features.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值