⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weatherwebpart.cs

📁 asp.net 2.0 WebPart应用. 使用Web部件创建模块化的Web门户应用; 个人化特性和自定义特性; 将自定义用户控件作为Web部件使用; 创建一个个人化特性的提供程序;
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace WingtipWebParts
{
	public class WeatherWebPart : WebPart
	{
		public WeatherWebPart()
		{
			this.Title = "Local Weather Report" + ZipCode;
			this.TitleIconImageUrl = @"~\img\Weather.gif";
			this.CatalogIconImageUrl = @"~\img\Weather.gif";
		}

		// The Zip code parameter
		private string _zipCode = string.Empty;

		// Dynamic script code to add to the Web part
		private const string HtmlFormat = @"
            <div id=""weatherView""></div>
            <script id=""weatherScript"" language=""javascript""></script>
            <script language=""javascript"">
            function CreateWeather(sAcid) {{
            	var oData = window['weatherScript'];
            	if (sAcid != '') {{
            		oData.onreadystatechange = ShowWeather;
            		oData.src = 'http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=' + sAcid;
            	}}
            }}
            
            function ShowWeather() {{

                if (typeof(makeWeatherObj) != 'undefined') {{
                                var oWea = new makeWeatherObj();
                var sTmp = '<b>Current Conditions</b><hr size=1>' +
                           '<table cellpadding=2 cellspacing=0 border=0><tr><td valign=""middle"">' +
                           '<img src=""http://www.msnbc.com/m/wea/i/36/' + oWea.swCIcon + '.gif"" align=absmiddle></td>' +
                           '<td>'+ oWea.swCity + ', ' + oWea.swSubDiv + '<br>' +
                           + oWea.swTemp + '&#176;F</td></tr></table>' + 
                           '<a href=""http://www.weather.com"">More weather information</a>';
            	document.all['weatherView'].innerHTML = sTmp;
                }}
            }}
            
            CreateWeather('{0}');
            </script>
            ";

		// ************************************************************************
		// Gets and sets the zip code to populate the part
		[Personalizable]
		[WebBrowsable]
		public string ZipCode
		{
			get { return _zipCode; }
			set { _zipCode = value; }
		}
		// ************************************************************************

		// ************************************************************************
		// Gets and sets the Web part collection of connection points
		protected override void RenderContents(HtmlTextWriter writer)
		{
			if ((_zipCode == null) || (_zipCode.Length == 0))
			{
				writer.Write("Select a zip code by personalizing this WebPart");
			}
			else
			{
				writer.Write(String.Format(HtmlFormat, _zipCode));
				writer.Write("&nbsp;");
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -