网页部件:门户的构建基石
1. 添加自定义天气网页部件
首先,在项目中添加一个名为CustomWeather.aspx的新网页,并像所有网页部件页面一样,添加一个WebPartManager。同时,需要在页面头部使用Register指令声明服务器控件,示例代码如下:
<%@ Register TagPrefix="wp" Namespace="WebPartTests" %>注册控件到页面后,就可以在ZoneTemplate中引用自定义网页部件,要确保使用与Register指令中声明的相同标签前缀,示例如下:
<asp:WebPartZone ID="WebPartZone1" runat="server"> <ZoneTemplate> <wp:CustomWeatherPart ID="CustomWeatherPart1" runat="server" Title="Weather Forecast" /> </ZoneTemplate> </asp:WebPartZone>当此页面在浏览器中显示时,会渲染天气网页部件,默认显示四天的天