<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Horn Network &#187; C#</title>
	<atom:link href="http://klcin.tw/net/category/net/c/feed" rel="self" type="application/rss+xml" />
	<link>http://klcin.tw/net</link>
	<description>Horn Network (.NET, ASP.NET, C#, VB.NET, JavaScript, Ubuntu, Android ...)</description>
	<lastBuildDate>Fri, 04 Mar 2011 07:25:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>[ASP.NET]將 Script 和 Image 封裝在 dll 內</title>
		<link>http://klcin.tw/net/script-image-webresource-dll</link>
		<comments>http://klcin.tw/net/script-image-webresource-dll#comments</comments>
		<pubDate>Sat, 28 Mar 2009 04:01:45 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[檔案下載]]></category>
		<category><![CDATA[GetWebResourceUrl]]></category>
		<category><![CDATA[PerformSubstitution]]></category>
		<category><![CDATA[RegisterClientScriptResource]]></category>
		<category><![CDATA[WebResource]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=115</guid>
		<description><![CDATA[本文介紹：如何將靜態檔案（如：.html files, .css files, image files, and script files）封裝在 dll 內及如何使用。（.NET 2.0 以上適合） 優點： 可避免靜態檔案放錯位置而造成錯誤。 許多第三方商用元件也是使用此法。 類別庫（DLL） 新增專案：Visual C#＼Windows＼類別庫 加入參考 System.Web 為了要繼承 System.Web.UI.WebControls.WebControl 及相關 functions 。 加入所需的靜態檔案，並將其建置動作設為「內嵌資源」 （如：下圖的 icon_Left_arrow.gif, icon_Right_arrow.gif , JScript1.js , JScript2.js） &#160; 修改 AssemblyInfo.cs為每一靜態檔案登記[assembly: System.Web.UI.WebResource(&#34;JsClassLibrary1.JScript1.js&#34;, &#34;application/x-javascript&#34;)] [assembly: System.Web.UI.WebResource(&#34;JsClassLibrary1.JScript2.js&#34;, &#34;application/x-javascript&#34;, PerformSubstitution=true)]&#160; // 要加 PerformSubstitution 才能在 js 中使用 WebResource [assembly: System.Web.UI.WebResource(&#34;JsClassLibrary1.icon_Right_arrow.gif&#34;, &#34;image/gif&#34;)] [assembly: System.Web.UI.WebResource(&#34;JsClassLibrary1.icon_Left_arrow.gif&#34;, [...]]]></description>
			<content:encoded><![CDATA[<h1></h1>
<p><strong>本文介紹</strong>：如何將靜態檔案（如：.html files, .css files, image files, and script files）封裝在 dll 內及如何使用。（.NET 2.0 以上適合）</p>
<p>優點：</p>
<ol>
<li>可避免靜態檔案放錯位置而造成錯誤。 </li>
<li>許多第三方商用元件也是使用此法。</li>
</ol>
<p>  <span id="more-115"></span><br />
<h2>類別庫（DLL）</h2>
<p>新增專案：Visual C#＼Windows＼類別庫</p>
<ol>
<li>加入參考 <strong>System.Web</strong>       <br />為了要繼承 System.Web.UI.WebControls.WebControl 及相關 functions 。 </li>
<li>加入所需的靜態檔案，並將其<strong>建置動作</strong>設為「<strong><font color="#ff0000">內嵌資源</font></strong>」       <br />（如：下圖的 icon_Left_arrow.gif, icon_Right_arrow.gif , JScript1.js , JScript2.js）       <br />&#160;<a href="http://klcin.tw/net/wp-content/uploads/2009/03/snap019.png"><img title="內嵌資源" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="273" alt="內嵌資源" src="http://klcin.tw/net/wp-content/uploads/2009/03/snap019-thumb.png" width="411" border="0" /></a> </li>
<li>修改 AssemblyInfo.cs<br />為每一靜態檔案登記<br />[assembly: System.Web.UI.WebResource(&quot;JsClassLibrary1.JScript1.js&quot;, &quot;application/x-javascript&quot;)]       <br />[assembly: System.Web.UI.WebResource(&quot;JsClassLibrary1.JScript2.js&quot;, &quot;application/x-javascript&quot;<strong><font color="#ff0000">, PerformSubstitution=true</font></strong>)]&#160; <font color="#008000">// 要加 PerformSubstitution 才能在 js 中使用 WebResource</font>      <br />[assembly: System.Web.UI.WebResource(&quot;JsClassLibrary1.icon_Right_arrow.gif&quot;, &quot;image/gif&quot;)]       <br />[assembly: System.Web.UI.WebResource(&quot;JsClassLibrary1.icon_Left_arrow.gif&quot;, &quot;image/gif&quot;)] </li>
<li>修改 Class1.cs      <br />繼承 WebControl 覆寫 OnPreRender 用 ClientScriptManager 註冊(<a href="http://msdn.microsoft.com/zh-tw/library/system.web.ui.clientscriptmanager.registerclientscriptresource(VS.80).aspx" target="_blank">RegisterClientScriptResource</a>) JS 檔。 </li>
<li>建置後產生 JsClassLibrary1.dll      <br /><a href="http://klcin.tw/net/wp-content/uploads/2009/03/snap021.png"><img title="dll" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="271" alt="dll" src="http://klcin.tw/net/wp-content/uploads/2009/03/snap021-thumb.png" width="286" border="0" /></a>&#160; </li>
</ol>
<h2>ASP.NET Web 應用程式</h2>
<p>新增專案：Visual C#＼Web＼ASP.NET Web 應用程式</p>
<ol>
<li>專案加入參考 JsClassLibrary1</li>
<li>修改 Default.aspx     <br />加上 &lt;%@ Register Assembly=&quot;JsClassLibrary1&quot; Namespace=&quot;JsClassLibrary1&quot; TagPrefix=&quot;klcintw&quot; %&gt; 即可使用 JScript1.js 或 JScript2.js 的 function。</li>
</ol>
<p>&#160;</p>
<h2>程式碼 </h2>
<h3>JScript1.js</h3>
<p>
<pre class="brush: js">function klcintw_Alert() {
  alert(&#039;TEST(&lt;%= WebResource(&quot;JsClassLibrary1.icon_Right_arrow.gif&quot;)%&gt;)&#039;);
}</pre>
</p>
<p>若在 AssemblyInfo.cs 沒有加上「PerformSubstitution="true"」<%%> 的內容會原原本本的顯示出來。 </p>
<h3>JScript2.js</h3>
<p>
<pre class="brush: js">function klcintw_Alert2() {
  alert(&#039;TEST2(&lt;%= WebResource(&quot;JsClassLibrary1.icon_Right_arrow.gif&quot;)%&gt;)&#039;);
}

function klcintw_Image(imgControl, bRight) {
  document.getElementById(imgControl).src =
    bRight ?
      &#039;&lt;%= WebResource(&quot;JsClassLibrary1.icon_Right_arrow.gif&quot;)%&gt;&#039; :
      &#039;&lt;%= WebResource(&quot;JsClassLibrary1.icon_Left_arrow.gif&quot;)%&gt;&#039;;
}
</pre>
</p>
<h3>Class1.cs</h3>
<p>
<pre class="brush: c#">using System;
using System.Collections.Generic;
using System.Text;

namespace JsClassLibrary1
{
  public class Class1 : System.Web.UI.WebControls.WebControl
  {
    protected override void OnPreRender(EventArgs e)
    {
      if (this.Page != null)
      {
        System.Web.UI.ClientScriptManager manager = this.Page.ClientScript;
        manager.RegisterClientScriptResource(typeof(Class1), &quot;JsClassLibrary1.JScript1.js&quot;);
        manager.RegisterClientScriptResource(typeof(Class1), &quot;JsClassLibrary1.JScript2.js&quot;);
      } // if
      base.OnPreRender(e);
    }
  }
}
</pre>
</p>
<h3>Default.aspx</h3>
<p>
<pre class="brush: html">&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;Default.aspx.cs&quot; Inherits=&quot;JsDllTest._Default&quot; %&gt;
&lt;%@ Register Assembly=&quot;JsClassLibrary1&quot; Namespace=&quot;JsClassLibrary1&quot; TagPrefix=&quot;klcintw&quot; %&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;head runat=&quot;server&quot;&gt;
  &lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
  &lt;div&gt;
  &lt;klcintw:Class1 ID=&quot;rs1&quot;  runat =&quot;server&quot;/&gt;
  &lt;input type=&quot;button&quot; value=&quot;TEST&quot; onclick=&quot;klcintw_Alert()&quot; /&gt;
  &lt;input type=&quot;button&quot; value=&quot;TEST2&quot; onclick=&quot;klcintw_Alert2()&quot; /&gt;&lt;br /&gt;
  &lt;input type=&quot;button&quot; value=&quot;klcintw_Image(R)&quot; onclick=&quot;klcintw_Image(&#039;myImg&#039;, true)&quot; /&gt;
  &lt;input type=&quot;button&quot; value=&quot;klcintw_Image(L)&quot; onclick=&quot;klcintw_Image(&#039;myImg&#039;, false)&quot; /&gt;
  &lt;img id=&#039;myImg&#039; alt=&quot;&quot; src=&quot;&quot; /&gt;
  &lt;/div&gt;
  &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
</p>
<h3>Default.aspx.cs</h3>
<p>
<pre class="brush: c#">using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JsDllTest
{
  public partial class _Default : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      // Get a ClientScriptManager reference from the Page class.
      ClientScriptManager cs = Page.ClientScript;
      //Get the type of the class.
      Type rsType = typeof(JsClassLibrary1.Class1);
      // 取得內嵌圖檔的網址
      string imgUrl = cs.GetWebResourceUrl(rsType, &quot;JsClassLibrary1.snap014.png&quot;);
    }
  }
}
</pre>
</p>
<p>&#160;</p>
<h4>檔案下載</h4>
<ul>
<li><a href='http://www.box.net/shared/2ixjdc6yyx' target='_blank'>程式碼（Box.net）</a></li>
</ul>
<h4>參考資料：</h4>
<ul>
<li>[Microsoft] <a href="http://support.microsoft.com/kb/910442" target="_blank">Working with Web Resources in ASP.NET 2.0</a> </li>
<li><a href="http://www.cnblogs.com/cry/archive/2009/03/27/1423243.html" target="_blank">如何把.js文件编译成dll供页面调用？ &#8211; 一只鞋</a> </li>
<li><a href='http://jackielin.cnblogs.com/archive/2005/11/29/286570.html' target='_blank'>在自定义Server Control中捆绑JS文件 Step by Step &#8211; BLACK JACK</a></li>
<li><a href="http://subocheng.blogspot.com/2007/11/aspnet-20-webresourceaxd-and-browser.html" target="_blank">Mr. NFrankenstein: ASP.NET 2.0 WebResource.axd and browser caching</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/script-image-webresource-dll/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Faves：2009/03/14：C# 3.0 &amp; IE8 web slice</title>
		<link>http://klcin.tw/net/faves%ef%bc%9a20090314%ef%bc%9ac-30-ie8-web-slice</link>
		<comments>http://klcin.tw/net/faves%ef%bc%9a20090314%ef%bc%9ac-30-ie8-web-slice#comments</comments>
		<pubDate>Sat, 14 Mar 2009 08:29:15 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[微筆記]]></category>
		<category><![CDATA[ie8]]></category>
		<category><![CDATA[web slice]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/faves%ef%bc%9a20090314%ef%bc%9ac-30-ie8-web-slice</guid>
		<description><![CDATA[c# 3.0 新Orcas語言特性：匿名類型-Scott Guthrie 博客中文版 # &#124; c# 3.0 匿名類型是個很方便的語言特性，允許開發人員在代碼內簡明地定義行內CLR類型，而不用提供一個正式的類定義聲明。雖然它們可以在很多場合下使用，但在使用LINQ查詢和轉換/構形數據時尤其有用。 C# 3.0 #var這個關鍵詞而是告訴編譯器在變量最先聲明時，從用來初始化變量的表達式推斷出變量的類型。 var product = new { FirstName = &#34;Scott&#34;, LastName = &#34;Guthrie&#34;, Age = 32 }; Console.WriteLine(product.FirstName); 新Orcas語言特性：Lambda表達式-Scott Guthrie 博客中文版 # &#124; c# 3.0,Lambda C# 3.0 #在C#裡，一個lambda表達式在句法上是寫成一個參數列表，隨後是 =&#62; 符號，隨後是表達式在調用時要運算的表達式或者語句塊 Console.WriteLine(&#34;AVG={0}&#34;, people.Average(p =&#62; p.Age)); IEnumerable results = people.Where(p =&#62; p.LastName == &#34;Guthrie&#34;); 新Orcas語言特性：擴展方法-Scott Guthrie [...]]]></description>
			<content:encoded><![CDATA[<h2>c# 3.0</h2>
<div class="fav">
<div class="fav-Subject"><a href="http://blog.joycode.com/scottgu/archive/2007/05/21/102887.aspx" target="_blank">新Orcas語言特性：匿名類型-Scott Guthrie 博客中文版</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142942681752" target="_blank">#</a> | c# 3.0</div>
<div class="fav-Note">
<blockquote>匿名類型是個很方便的語言特性，允許開發人員在代碼內簡明地定義行內CLR類型，而不用提供一個正式的類定義聲明。雖然它們可以在很多場合下使用，但在使用LINQ查詢和轉換/構形數據時尤其有用。</p></blockquote>
<p>C# 3.0        </p>
<p>#var這個關鍵詞而是告訴編譯器在變量最先聲明時，從用來初始化變量的表達式推斷出變量的類型。         <br />var product = new { FirstName = &quot;Scott&quot;, LastName = &quot;Guthrie&quot;, Age = 32 };         <br />Console.WriteLine(product.FirstName);</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://blog.joycode.com/scottgu/archive/2007/04/09/100744.aspx" target="_blank">新Orcas語言特性：Lambda表達式-Scott Guthrie 博客中文版</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142942302549" target="_blank">#</a> | c# 3.0,Lambda</div>
<div class="fav-Note">
<p>C# 3.0        </p>
<p>#在C#裡，一個lambda表達式在句法上是寫成一個參數列表，隨後是 =&gt; 符號，隨後是表達式在調用時要運算的表達式或者語句塊         <br />Console.WriteLine(&quot;AVG={0}&quot;, people.Average(p =&gt; p.Age));         <br />IEnumerable
<person> results = people.Where(p =&gt; p.LastName == &quot;Guthrie&quot;);</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://blog.joycode.com/scottgu/archive/2007/04/07/100611.aspx" target="_blank">新Orcas語言特性：擴展方法-Scott Guthrie 博客中文版</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142942190674" target="_blank">#</a> | c# 3.0,LINQ</div>
<div class="fav-Note">
<p>C# 3.0        </p>
<p>#擴展方法允許開發人員往一個現有的CLR類型的公開契約(contract)中添加新的方法，而不用生成子類或者重新編譯原來的類型。擴展方法有助於把今天動態語言中流行的對duck typing的支持之靈活性，與強類型語言之性能和編譯時驗證融合起來。
<pre class="brush: c#">
public static class ScottGuExtensions
{
         public static bool IsValidEmailAddress(this string s)
         {
         Regex regex = new Regex(@&amp;quot;^[w-.]+@([w-]+.)+[w-]{2,4}$&amp;quot;);
         return regex.IsMatch(s);
         }
}
</pre>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://blog.joycode.com/scottgu/archive/2007/04/24/101654.aspx" target="_blank">新Orcas語言特性：查詢句法-Scott Guthrie 博客中文版</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142931314080" target="_blank">#</a> | c# 3.0,LINQ</div>
<div class="fav-Note">
<p>C# 3.0        </p>
<p>Language-Integrated Query         </p>
<p>*每個查詢表達式的句法從from子句開始，以select或group子句結束。from子句表示你要查詢什麼數據。select子句則表示你要返回什麼數據，且應該以什麼構形返回。         </p>
<p>*在一個查詢句法表達式開頭的&quot;from&quot; 子句和結尾的&quot;select&quot;子句之間，你可以使用最常見的LINQ查詢運算符來過濾和轉換你在查詢的數據。兩個最常用的子句是&quot;where&quot;和&quot;orderby&quot;。這兩個子句處理對結果集的過濾和排序。         </p>
<p>#用投影(Projection)來轉換數據         <br />#理解延遲執行(Deferred Execution)和使用ToList() 和ToArray()</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://msdn.microsoft.com/zh-tw/library/bb383815.aspx" target="_blank">Visual C# 的新功能</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142930744643" target="_blank">#</a> | c# 3.0,msdn</div>
<div class="fav-Note">
<p>C# 3.0</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://www.dotblogs.com.tw/chhuang/archive/2008/05/19/4078.aspx" target="_blank">C# 3.0 &#8211; Object And Collection Initializers &#8211; 瓶水相逢.Net- 點部落</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142930489908" target="_blank">#</a> | C# 3.0</div>
<div class="fav-Note">
<blockquote>C# 3.0 新語法</p></blockquote>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://blog.joycode.com/scottgu/archive/2007/03/11/95954.aspx" target="_blank">Orcas中C#語言的新特性：自動屬性，對象初始化器，和集合初始化器-Scott Guthrie 博客中文版</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142930412111" target="_blank">#</a> | C# 3.0</div>
<div class="fav-Note">
<p>C# 3.0 的特色        </p>
<p>新的C#語言特性：自動屬性(Automatic Properties)         <br />public class Person {         <br />public string FirstName { get; set; }         <br />public string LastName { get; set; }         <br />public int Age { get; set; }         <br />}         </p>
<p>C#和VB語言的新特性：對象初始化器(Object Initializers)         <br />Person person = new Person { FirstName=&quot;Scott&quot;, LastName=&quot;Guthrie&quot;, Age=32 };         </p>
<p>C#和VB語言的新特性：集合初始化器(Collection Initializers)         <br />List
<person> people = new List
<person> {         <br />new Person { FirstName = &quot;Scott&quot;, LastName = &quot;Guthrie&quot;, Age = 32 },         <br />new Person { FirstName = &quot;Bill&quot;, LastName = &quot;Gates&quot;, Age = 50 },         <br />new Person { FirstName = &quot;Susanne&quot;, LastName = &quot;Guthrie&quot;, Age = 32 }         <br />};</p>
</p></div>
</p></div>
<p> <span id="more-109"></span><br />
<h2>Web Slices</h2>
<p>&#160;</p>
<p><a href="http://msdn.microsoft.com/en-us/library/cc956158%28VS.85%29.aspx" target="_blank">Web Slices</a></p>
<div class="fav">
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.143006540953" target="_blank">#</a> | web slice,msdn</div>
<div class="fav-Note">
<p>This section offers conceptual overview material for Web Slices, introduced with Windows Internet Explorer 8. A Web Slice uses simple HTML markup to represent a clipping of a Web page, enabling users to subscribe to content directly within a Web page.        </p>
<p>#Subscribing to Content with Web Slices         <br />#Web Slice Format Specification &#8211; Version 0.9         <br />#Web Slice Icon Guidelines</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://blog.xuite.net/misgarlic/weblogic/22708186" target="_blank">IE8 新功能之網頁快訊 &#8211; web slice!：不大會寫程式：Xuite日誌</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.143006124703" target="_blank">#</a> | ie8,Web Slice</div>
<div class="fav-Note">
<blockquote>其實 web slice 超級阿呆, 只要把某段 html code, 以微軟設定的 div class 包起來, 就算結束了</p></blockquote>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://msdn.microsoft.com/zh-tw/ie/dd366103.aspx#Internet_Explorer_8_5" target="_blank">邊做邊學Internet Explorer 8：為你的網站穿上新衣 &#8211; Internet Explorer 8 新功能</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.143005888781" target="_blank">#</a> | ie8,Web Slice</div>
<div class="fav-Note">
<blockquote>Web Slice 允許使用者訂閱某一個網頁中的特定區段，一旦訂閱後，該區段便會出現在 Internet Explorer 8 的工具列上，使用者可以直接點擊該按紐查看該區段的內容，更好的是該區段會自動連往原始網頁進行更新。</p></blockquote>
</p></div>
</p></div>
<h2>其它</h2>
<p>&#160;</p>
<div class="fav">
<div class="fav-Subject"><a href="http://demo.tc/view.aspx?id=482" target="_blank">Subst內建的虛擬磁碟命令 &#8211; demo小鋪</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142958992281" target="_blank">#</a> | dos</div>
<div class="fav-Note">
<blockquote>把資料夾設定成虛擬磁碟機</p></blockquote>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://demo.tc/view.aspx?id=478" target="_blank">把js包起來一次下載加快網頁速度 &#8211; demo小鋪</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142958924218" target="_blank">#</a> | javascript</div>
<div class="fav-Note">
<blockquote>ScriptReferenceProfiler(<a href="http://tinyurl.com/ddu8pp" target="_blank">http://tinyurl.com/ddu8pp</a>)</p></blockquote>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://demo.tc/view.aspx?id=477" target="_blank">切割版面的技巧使用CSS Sprites &#8211; demo小鋪</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142958850874" target="_blank">#</a> | css</div>
<div class="fav-Note">
<p>CSS 切圖減少 request。</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://mattberseth.com/blog/2007/10/improving_the_presentation_of.html" target="_blank">Matt Berseth: Improving the Presentation of an Extra-Wide GridView</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142943588158" target="_blank">#</a> | ajax,asp.net,gridview</div>
<div class="fav-Note">
<blockquote>: Matt Berseth寫了一篇很好的文章，示範如何添加一些非常酷的CSS和AJAX效果來改進ASP.NET GridView控件的可讀性。</p></blockquote>
<p>十字加亮</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://aspnet.4guysfromrolla.com/articles/101707-1.aspx" target="_blank">ASP.NET.4GuysFromRolla.com: Sending Email in ASP.NET 2.0: Reply-To, Priority, and Read Receipts</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142943413002" target="_blank">#</a> | smtp,asp.net,vb.net</div>
<div class="fav-Note">
<blockquote>在ASP.NET 2.0中發送郵件：答覆地址，發送優先設置和要求閱讀收據的問題: Scott Mitchell寫了一篇非常有用的文章，描述如何使用.NET 2.0和ASP.NET 2.0中的一些高級的email特性。</p></blockquote>
<p>Dim mm As New MailMessage(fromAddress, toAddress)         <br />mm.Subject = subject         <br />mm.Body = body         <br />mm.ReplyTo = New MailAddress(&quot;答覆地址&quot;)         <br />mm.Priority = MailPriority.High &#8216; 優先         <br />mm.Headers.Add(&quot;Disposition-Notification-To&quot;, &quot;回條地址&quot;)</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://www.asp.net/learn/videos/" target="_blank">Videos for ASP.NET 2.0 Beginners</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142929636455" target="_blank">#</a> | asp.net,javascript,css,video</div>
<div class="fav-Note">
<blockquote>This video series includes over six hours of video-based instruction that walks you through creating and deploying your first web page, to creating a fully-functioning &#8230;</p></blockquote>
<p>給 ASP.NET 2.0 初學者的線上教學影片</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://www.codeplex.com/ASPNETRSSToolkit" target="_blank">ASP.NET RSS Toolkit &#8211; Home</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142929454627" target="_blank">#</a> | rss,codeplex,asp.net</div>
<div class="fav-Note">
<p>* Consuming feeds.        <br />* Support for generation of feeds in ASP.NET application         <br />* Set of classes for programmatic consumption and generation of RSS feed in a late-bound way, without using strongly types generated classes</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://demo.tc/view.aspx?id=446" target="_blank">ASP.NET RSS Toolkit快速滿足你對於RSS的需求 &#8211; demo小鋪</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142927064111" target="_blank">#</a> | asp.net,rss</div>
<div class="fav-Note">
<blockquote>在.NET3.5後有ServiceModel.Syndication可以快速處理RSS但還是麻煩阿&#8230;最近因為ASP.NET MVC的關係常晃Scott Guthrie&#8217;s的Blog意外看到了這個好東西，非常簡單的讓你使用別人的RSS以及創建自己的RSS。</p></blockquote>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://aspnetresources.com/blog/ms_ajax_cheat_sheets_batch2.aspx" target="_blank">Microsoft AJAX Library Cheat Sheets</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142926301455" target="_blank">#</a> | AJAX,速查表</div>
<div class="fav-Note">
<p>http://aspnetresources.com/downloads/ms_ajax_library_cheat_sheets1.zip</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://demo.tc/view.aspx?id=470" target="_blank">實做Microsoft Chart Controls折騰了我一天&#8230; &#8211; demo小鋪</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142918525471" target="_blank">#</a> | chart</div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=zh-tw&amp;FamilyID=130f7986-bf49-4fe5-9ca8-910ae6ea442c" target="_blank">Microsoft Chart Controls for Microsoft .NET Framework 3.5</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142918444221" target="_blank">#</a> | MSDN_Download,chart</div>
<div class="fav-Note">
<blockquote>適用於 .NET Framework 3.5 SP1 的 ASP.NET 和 Windows Form 圖表控制項</p></blockquote>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://blog.miniasp.com/post/2008/10/Useful-aspnet-and-winform-charting-control-from-Microsoft.aspx" target="_blank">介紹好用元件：Microsoft Chart Controls for .NET 3.5</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142918409377" target="_blank">#</a> | .net,asp.net,chart</div>
<div class="fav-Note">
<blockquote>2007/6/4微軟購買了 Dundas 公司所有的 Dundas Data Visualization 元件版權。後來公佈了 Microsoft Chart Controls for Microsoft .NET Framework 3.5 (http://tinyurl.com/amkh94) 控制項元件，可以同時支援在 ASP.NET 與 Windows Form 環境開發圖表相關的客製化應用程式，而這一套控制項的核心正是微軟跟 Dundas 公司購買的那些 Dundas Data Visualization 元件。</p></blockquote>
<p>Microsoft .NET Framework 3.5 SP1         <br />延伸閱讀：http://tinyurl.com/d6datb , http://tinyurl.com/df69gn ,</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://www.backup.idv.tw/viewtopic.php?p=2582" target="_blank">[分享] DOS 批次檔 batch file 取得日期為變數值的運用</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142878217406" target="_blank">#</a> | batch</div>
<div class="fav-Note">
<p>@For /f &quot;tokens=1-3 delims=/ &quot; %%a in (&#8216;date /t&#8217;) do (set date=%%a-%%b-%%c)        <br />指令&quot;date /t&quot;輸出&quot;2009/03/13 星期五&quot;         <br />@echo The date is %date% 輸出2009-03-13         </p>
<p>@For /f &quot;tokens=2-3 delims=: &quot; %%a in (&#8216;time /t&#8217;) do (set time=%%a:%%b)         <br />指令&quot;time /t&quot;輸出&quot;上午 12:14&quot;         <br />@echo The time is %time% 輸出12:13         </p>
<p>@IF NOT EXIST %date% mkdir %date%         <br />如果該目錄不存在就建立         </p>
<p>@set dailylog=%date%.log         <br />@IF NOT EXIST %date%/%dailylog% echo ### &gt; %date%/%dailylog%         <br />如果檔案不存在就建立</p>
</p></div>
</p></div>
<div class="fav">
<div class="fav-Subject"><a href="http://betterexplained.com/articles/speed-up-your-javascript-load-time/" target="_blank">Speed Up Your Javascript Load Time | BetterExplained</a></div>
<div class="fav-Tags"><a href="http://faves.com/users/klcintw/dot/370618.142789618868" target="_blank">#</a> | javascript,tips</div>
<div class="fav-Note">
<p>[找出瓶頸]        <br />1.Firefox web-developer toolbar(<a href="http://tinyurl.com/p336d" target="_blank">http://tinyurl.com/p336d</a>)         <br />2.Firebug Plugin(<a href="http://tinyurl.com/ehh7l" target="_blank">http://tinyurl.com/ehh7l</a>)         <br />3.OctaGate SiteTimer(<a href="http://tinyurl.com/ydzryc" target="_blank">http://tinyurl.com/ydzryc</a>)         <br />[壓縮程式碼]         <br />1.JSLint(<a href="http://tinyurl.com/y8guls" target="_blank">http://tinyurl.com/y8guls</a>)分析         <br />2.Rhino(<a href="http://tinyurl.com/dfa3ub" target="_blank">http://tinyurl.com/dfa3ub</a>)壓縮         <br />[將程式碼放在後面]         <br />[動態載入JS檔]         <br />[用timer延遲執行]         <br />[快取]         <br />[整合成一個JS檔]</p>
</p></div>
</p></div>
<div class="fav-Rank">
<h4>Rank</h4>
<li>c# 3.0 = 7 </li>
<li>asp.net = 6 </li>
<li>web slice = 3 </li>
<li>chart = 3 </li>
<li>javascript = 3 </li>
<li>linq = 2 </li>
<li>ajax = 2 </li>
<li>ie8 = 2 </li>
<li>css = 2 </li>
<li>codeplex = 2 </li>
<li>msdn = 2 </li>
<li>rss = 2 </li></div>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/faves%ef%bc%9a20090314%ef%bc%9ac-30-ie8-web-slice/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HtmlScreenCapture – Live Writer SDK 中好用的 class</title>
		<link>http://klcin.tw/net/htmlscreencapture</link>
		<comments>http://klcin.tw/net/htmlscreencapture#comments</comments>
		<pubDate>Sun, 08 Mar 2009 09:47:38 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WLW-SDK]]></category>
		<category><![CDATA[HtmlScreenCapture]]></category>
		<category><![CDATA[Windows Live Writer]]></category>
		<category><![CDATA[截圖]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=90</guid>
		<description><![CDATA[HtmlScreenCapture 可以將 HTML 內容（或指定網址）快照成圖檔。（Provides the ability to capture HTML content into a bitmap. [#]） 要參考 C:\Program Files\Windows Live\Writer\WindowsLive.Writer.Api.dll 程式碼： using System; using System.Collections.Generic; using System.Text; using WindowsLive.Writer.Api; class Program { static void Main(string[] args) { // 從指定網址截圖 WindowsLive.Writer.Api.HtmlScreenCapture capture = new HtmlScreenCapture(new Uri(&#34;http://tw.yahoo.com&#34;), 1024/*寬度*/); System.Drawing.Bitmap bmp = capture.CaptureHtml(5000/*timeoutMs*/); bmp.Save(@&#34;C:\1.png&#34;, System.Drawing.Imaging.ImageFormat.Png); // 從 html 內容截圖 WindowsLive.Writer.Api.HtmlScreenCapture [...]]]></description>
			<content:encoded><![CDATA[<p><strong>HtmlScreenCapture </strong></p>
<p>可以將 HTML 內容（或指定網址）快照成圖檔。（Provides the ability to capture HTML content into a bitmap. [<a href="http://msdn.microsoft.com/en-us/library/aa738928.aspx" target="_blank">#</a>]）</p>
<ul>
<li>要參考 C:\Program Files\Windows Live\Writer\WindowsLive.Writer.Api.dll</li>
</ul>
<h2>程式碼：</h2>
<pre class="brush: csharp">
using System;
using System.Collections.Generic;
using System.Text;
using WindowsLive.Writer.Api;

class Program
{
    static void Main(string[] args)
    {
        // 從指定網址截圖
        WindowsLive.Writer.Api.HtmlScreenCapture capture =
            new HtmlScreenCapture(new Uri(&quot;http://tw.yahoo.com&quot;), 1024/*寬度*/);
        System.Drawing.Bitmap bmp = capture.CaptureHtml(5000/*timeoutMs*/);
        bmp.Save(@&quot;C:\1.png&quot;, System.Drawing.Imaging.ImageFormat.Png);

        // 從 html 內容截圖
        WindowsLive.Writer.Api.HtmlScreenCapture capture2 = new HtmlScreenCapture(
            &quot;&lt;h1&gt;中文測試&lt;/h1&gt;&lt;p&gt;一些&lt;b&gt;文字&lt;/b&gt;&quot;+
            &quot;和一個&lt;a href=&#039;http://klcin.tw/net&#039;&gt;連結&lt;/a&gt;&lt;/p&gt;&quot;, 200);
        System.Drawing.Bitmap bmp2 = capture2.CaptureHtml(5000);
        bmp2.Save(@&quot;C:\2.png&quot;, System.Drawing.Imaging.ImageFormat.Png);

    } // Main
} // class
</pre>
<p>輸出結果：</p>
<p><img src="http://klcin.tw/net/wp-content/uploads/2009/03/1-150x150.png" alt="從指定網址截圖" title="從指定網址截圖" width="150" height="150" class="alignnone size-thumbnail wp-image-92" /><br />
<img src="http://klcin.tw/net/wp-content/uploads/2009/03/2-150x76.png" alt="從 html 內容截圖" title="從 html 內容截圖" width="150" height="76" class="alignnone size-thumbnail wp-image-91" /></p>
<h4>參考資料：</h4>
<ul>
<li>MSDN：<a href="http://msdn.microsoft.com/en-us/library/aa738928.aspx" target="_blank">HtmlScreenCapture Class</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/htmlscreencapture/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C#]程式幫您按按鈕（SendKey &amp; SendMessage）</title>
		<link>http://klcin.tw/net/csharp-sendkey-sendmessage</link>
		<comments>http://klcin.tw/net/csharp-sendkey-sendmessage#comments</comments>
		<pubDate>Fri, 05 Dec 2008 17:31:21 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[問題與解決]]></category>
		<category><![CDATA[BN_CLICKED]]></category>
		<category><![CDATA[FindWindow]]></category>
		<category><![CDATA[FindWindowEx]]></category>
		<category><![CDATA[GetDlgCtrlID]]></category>
		<category><![CDATA[SendKey]]></category>
		<category><![CDATA[SendMessage]]></category>
		<category><![CDATA[WM_COMMAND]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=87</guid>
		<description><![CDATA[前言 專案中有個程式負責透過 ACDSee 列印（ProcessStartInfo.Verb=”Print”）各種圖檔。但 ACDSee 在列印時會出現讓使用者設定格式、頁首頁尾、印表機選項的視窗出現，要按下「列印(P)」之後才會真的開始列印，所以程式必須在開始工作時偵測 ACDSee 的狀態並且按下列印鈕。 方法如下： hWnd = FindWindow(null,”ACDSee &#8211; 列印”); // 尋找 ACDSee 的列印視窗 SetForegroundWindow(hWnd); // 將視窗帶到前景 SendKeys.SendWait(“{ENTER}”); // 送出 ENTER 鍵按列印鈕 事前測試都OK，但安裝到客戶的機器上卻經常發生沒有自動按列印鈕而卡住的問題。原以為是被其它程式干擾{ENTER}的發送，但奇怪的是同事在現場怎麼測試都無法重現問題，一離開不久客戶就反應問題又發生了。 最後，細心的同事發現是因為機器一段時間沒人操作就會被鎖住(lock)，流程卡住的問題就開始了！ 推測：當系統 lock 時，畫面看不到 ACDSee 的視窗（但 FindWindow 可以找到）所以 SendKey 無法送到正確的視窗。 解法 用 SendMessage 發送 WM_COMMAND 程式（C版） HWND hWnd = ::FindWindow(NULL, &#34;ACDSee - Print&#34;); if(NULL != hWnd) { HWND [...]]]></description>
			<content:encoded><![CDATA[<h2>前言</h2>
<p>專案中有個程式負責透過 <a href="http://tw.acdsee.com/zh-tw/" target="_blank">ACDSee</a> 列印（ProcessStartInfo.Verb=”Print”）各種圖檔。但 ACDSee 在列印時會出現讓使用者設定格式、頁首頁尾、印表機選項的視窗出現，要按下「列印(P)」之後才會真的開始列印，所以程式必須在開始工作時偵測 ACDSee 的狀態並且按下列印鈕。</p>
<p>方法如下：</p>
<ol>
<li>hWnd = <a href="http://msdn.microsoft.com/en-us/library/ms633499.aspx" target="_blank">FindWindow</a>(null,”ACDSee &#8211; 列印”); // 尋找 ACDSee 的列印視窗 </li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms633539(VS.85).aspx" target="_blank">SetForegroundWindow</a>(hWnd); // 將視窗帶到前景 </li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.sendwait(VS.80).aspx" target="_blank">SendKeys.SendWait</a>(“{ENTER}”); // 送出 ENTER 鍵按列印鈕 </li>
</ol>
<p>事前測試都OK，但安裝到客戶的機器上卻經常發生沒有自動按列印鈕而卡住的問題。原以為是被其它程式干擾{ENTER}的發送，但奇怪的是同事在現場怎麼測試都無法重現問題，一離開不久客戶就反應問題又發生了。</p>
<p>最後，細心的同事發現是因為機器一段時間沒人操作就會被鎖住(lock)，流程卡住的問題就開始了！</p>
<p>推測：當系統 lock 時，畫面看不到 ACDSee 的視窗（但 FindWindow 可以找到）所以 SendKey 無法送到正確的視窗。</p>
<p>  <span id="more-87"></span><br />
<h2>解法</h2>
<p>用 <a href="http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx" target="_blank">SendMessage</a> 發送 WM_COMMAND </p>
<h3>程式（C版）</h3>
<pre class="brush: c#">
    HWND hWnd = ::FindWindow(NULL, &quot;ACDSee - Print&quot;);
    if(NULL != hWnd)
    {
        HWND hButton = ::FindWindowEx(hWnd, NULL, &quot;BUTTON&quot;, &quot;&amp;Print&quot;);
        if(NULL != hButton)
        {
            ::PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(::GetDlgCtrlID(hButton), BN_CLICKED),(LPARAM)hButton);
        }
        else
        {
            AfxMessageBox(&quot;Can not find [Print]&quot;);
        }
    }
    else
    {
        AfxMessageBox(&quot;Can not find [ACDSee - Print]&quot;);
    }</pre>
<p>&#160;</p>
<h3>程式（C#版）</h3>
<pre class="brush: c#">
IntPtr hWnd = FindWindow(null, &quot;ACDSee - 列印&quot;);
if ( !hWnd.Equals(IntPtrZero) )
{
	IntPtr hButton = FindWindowEx(hWnd, 0, &quot;BUTTON&quot;, &quot;列印(&amp;P)&quot;);
	if ( !hButton.Equals(IntPtrZero) )
	{
		SendMessage(hWnd, WM_COMMAND, GetDlgCtrlID(hButton) , hButton);
	} // if
} // if

/* API 定義*/
[DllImport(&quot;User32.dll&quot;,EntryPoint=&quot;FindWindow&quot;)]
private static extern IntPtr FindWindow(string lpClassName,string lpWindowName); 

[DllImport(&quot;User32.dll&quot;)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, int hwndChildAfter, string lpszClass, string lpszWindow); 

[DllImport(&quot;user32.dll&quot;)]
public static extern int GetDlgCtrlID(IntPtr hWnd);

[DllImport(&quot;user32.dll&quot;, EntryPoint = &quot;SendMessageA&quot;)]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);

private const int WM_COMMAND = 0x111;
private const int BN_CLICKED = 0;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/csharp-sendkey-sendmessage/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用 ASP.NET 製作 Google gadget</title>
		<link>http://klcin.tw/net/aspnet-google-gadget</link>
		<comments>http://klcin.tw/net/aspnet-google-gadget#comments</comments>
		<pubDate>Thu, 14 Aug 2008 13:10:18 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Google Gadget]]></category>
		<category><![CDATA[檔案下載]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[gadget]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=59</guid>
		<description><![CDATA[緣起： 客戶要求將現有網站部份資訊製作成 Google Gadget（Google 小工具）並希望在短時間內能夠上線使用，以求績效。 在考量時間不多且缺乏開發 gadget 經驗，決定採用 Google小工具API上所建議【將現有網頁或應用程式轉變為小工具】的方式來實作。 在客戶多次變更需求的過程中累積一些開發心得記錄下來和大家分享。 本文將集中在 ASP.NET 程式(.cs)和網頁(.aspx)部份，其它 gadget 相關技術資訊請自行參考 Google API 文件。 讀寫使用者的設定值 動態調整 gadget 高度 Base Class 基礎類別 下載 baseGadget.cs 。 default.xml 組態檔 8. &#60;Require feature=&#34;setprefs&#34; /&#62; 表示 gadget 要有「使用者偏好設定」功能。[API文件] 9. &#60;Require feature=&#34;dynamic-height&#34; /&#62; 表示 gadget 要有「動態高度」功能。[API文件] 11,15,17. 本例中所使用的3種資料型態 enum,list,hidden。[API文件] default.aspx.cx 程式 public partial class _Default : // [...]]]></description>
			<content:encoded><![CDATA[</p>
<h2><a href="http://klcin.tw/net/wp-content/uploads/2008/08/snap022.png"><img title="google gadget" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="google gadget" src="http://klcin.tw/net/wp-content/uploads/2008/08/snap022-thumb.png" width="178" align="right" border="0" /></a> 緣起：</h2>
<p>客戶要求將現有網站部份資訊製作成 Google Gadget（Google 小工具）並希望在短時間內能夠上線使用，以求績效。</p>
<p>在考量時間不多且缺乏開發 gadget 經驗，決定採用 Google小工具API上所建議【<a href="http://www.google.com/intl/zh-TW/apis/gadgets/fundamentals.html#Existing" target="_blank">將現有網頁或應用程式轉變為小工具</a>】的方式來實作。</p>
<p>在客戶多次變更需求的過程中累積一些開發心得記錄下來和大家分享。</p>
<p>本文將集中在 ASP.NET 程式(.cs)和網頁(.aspx)部份，其它 gadget 相關技術資訊請自行參考 <a href="http://code.google.com/apis/gadgets/docs/dev_guide.html" target="_blank">Google API 文件</a>。</p>
<ul>
<li>讀寫使用者的設定值 </li>
<li>動態調整 gadget 高度 </li>
</ul>
<p> <span id="more-59"></span><br />
<h2>Base Class 基礎類別</h2>
<p><a href='http://www.box.net/shared/gzjyqkea49' target='_blank'>下載 baseGadget.cs</a> 。</p>
<h2>default.xml 組態檔</h2>
<p><a href="http://klcin.tw/net/wp-content/uploads/2008/08/snap020.png"><img title="default.xml" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="179" alt="default.xml" src="http://klcin.tw/net/wp-content/uploads/2008/08/snap020-thumb.png" width="402" border="0" /></a> </p>
<p>8. &lt;Require feature=&quot;setprefs&quot; /&gt; 表示 gadget 要有「使用者偏好設定」功能。[<a href="http://www.google.com.tw/intl/zh-TW/apis/gadgets/reference.html" target="_blank">API文件</a>]     <br />9. &lt;Require feature=&quot;dynamic-height&quot; /&gt; 表示 gadget 要有「動態高度」功能。[<a href="http://www.google.com.tw/intl/zh-TW/apis/gadgets/ui.html#Dyn_Height" target="_blank">API文件</a>]     <br />11,15,17. 本例中所使用的3種資料型態 enum,list,hidden。[<a href="http://www.google.com/intl/zh-TW/apis/gadgets/fundamentals.html#Datatypes" target="_blank">API文件</a>]</p>
<h2>default.aspx.cx 程式</h2>
<p>
<pre class="brush: c#">public partial class _Default :
    // 繼承 baseGadget 類別
    klcintw.network.google.gadget.baseGadget
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // 取得Google相關功能的 js library
        base.RegisterGadgetScriptInclude();
        // 使用動態調整高度的功能
        base.DynamicHeight();

        // 輸出各取得設定值
        Response.Write(string.Format(&quot;tEnum = {0}&lt;br /&gt;&quot;,
            base.prefs_getString(&quot;tEnum&quot;)));
        Response.Write(string.Format(&quot;tList = {0}&lt;br /&gt;&quot;,
            base.prefs_getString(&quot;tList&quot;)));
        Response.Write(string.Format(&quot;tHidden = {0}&lt;br /&gt;&quot;,
            base.prefs_getString(&quot;tHidden&quot;)));
    }
}
</pre>
</p>
<h2>default.aspx 網頁</h2>
<p>
<pre class="brush: html">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;Horn Network&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
body {font-size:10pt;}
input.button {width:100px;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;hr size=&#039;1&#039; /&gt;
&lt;a href=&quot;http://klcin.tw/net&quot;&gt;Google Gadget with ASP.NET 示範&lt;/a&gt;
&lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
&lt;hr size=&#039;1&#039; /&gt;
&lt;table style=&quot;font-size:8pt;&quot; width=&quot;100%&quot;&gt;&lt;tr&gt;&lt;td&gt;
prefs.getString(&#039;XXX&#039;)&lt;br /&gt;
&lt;input type=&quot;button&quot; class=&#039;button&#039; value=&quot;tEnum&quot; onclick=&quot;alert(prefs.getString(&#039;tEnum&#039;));&quot; /&gt;&lt;br /&gt;
&lt;input type=&quot;button&quot; class=&#039;button&#039; value=&quot;tList&quot; onclick=&quot;alert(prefs.getString(&#039;tList&#039;));&quot; /&gt;&lt;br /&gt;
&lt;input type=&quot;button&quot; class=&#039;button&#039; value=&quot;tHidden&quot; onclick=&quot;alert(prefs.getString(&#039;tHidden&#039;));&quot; /&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td&gt;
_args()[&#039;up_XXX&#039;]&lt;br /&gt;
&lt;input type=&quot;button&quot; class=&#039;button&#039; value=&quot;tEnum&quot; onclick=&quot;alert(_args()[&#039;up_tEnum&#039;]);&quot; /&gt;&lt;br /&gt;
&lt;input type=&quot;button&quot; class=&#039;button&#039; value=&quot;tList&quot; onclick=&quot;alert(_args()[&#039;up_tList&#039;]);&quot; /&gt;&lt;br /&gt;
&lt;input type=&quot;button&quot; class=&#039;button&#039; value=&quot;tHidden&quot; onclick=&quot;alert(_args()[&#039;up_tHidden&#039;]);&quot; /&gt;&lt;br /&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;hr size=&#039;1&#039; /&gt;
編輯tHidden欄位：&lt;input type=&quot;text&quot; id=&quot;txtHidden&quot; value=&#039;&lt;%=prefs_getString(&quot;tHidden&quot;)%&gt;&#039; /&gt;
&lt;input type=&quot;button&quot; value=&quot;儲存&quot; onclick=&quot;fnSave();&quot; /&gt;

&lt;input type=&quot;hidden&quot; id=&quot;tHidden&quot; name=&quot;tHidden&quot; value=&#039;&lt;%=prefs_getString(&quot;tHidden&quot;)%&gt;&#039; /&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var prefs = new _IG_Prefs();
function fnSave() {
    _gel(&#039;tHidden&#039;).value = _gel(&#039;txtHidden&#039;).value;
    prefs.set(&quot;tHidden&quot;, _gel(&#039;tHidden&#039;).value);

    window.setTimeout(reloadGadget, 2000);
}
function reloadGadget() {
    _gel(&#039;form1&#039;).submit();
}
&lt;/script&gt;
&lt;/html&gt;</pre>
</p>
<h3>在 client 端讀取「使用者偏好設定」的方法</h3>
<ol>
<li>_args()['<strong><font color="#ff0000">up_</font></strong>tEnum']); // 要在變數前面加 up_ </li>
<li>var prefs = new _IG_Prefs();      <br />prefs.getString(&#8216;tEnum&#8217;); </li>
</ol>
<h3>在 client 端寫入「使用者偏好設定」的方法</h3>
<ul>
<li>var prefs = new _IG_Prefs();      <br />prefs.set(&quot;tHidden&quot;, ‘123’); </li>
</ul>
<h3>在 client 端動態調整高度的方法</h3>
<ul>
<li>_IG_AdjustIFrameHeight(); // 需要調整高度時即呼叫 </li>
</ul>
<h4>備註：</h4>
</p>
<ol>
<li>其實 gadget 的所有參數都是由 url 傳遞的，如：      <br /><textarea>http://textar.twbbs.org/Gadget/default.aspx?up_tEnum=1&amp;upt_tEnum=enum&amp;up_tList=123%7CASD%7C%E6%96%87%E5%AD%97&amp;upt_tList=list&amp;up_tHidden=%E4%B8%AD%E6%96%87TEST&amp;upt_tHidden=hidden&amp;lang=zh-TW&amp;country=us&amp;.lang=zh-TW&amp;.country=us&amp;synd=ig&amp;mid=148&amp;ifpctok=6871384243896489231&amp;parent=http://www.google.com&amp;libs=NHtl9J3jsts/lib/libcore.js,_LVLbGtgvkY/lib/libdynamic-height.js,MJLTofH-Kpk/lib/libsetprefs.js</textarea>       <br />所以參數資料量是有限制的。 </li>
<li>為了讓 client 端（用 javascript）變更的設定值能傳回 server 端，必須要 post 回去。      <br />而此時就不能從 url 讀設定值因為不會變。       <br />所以要在 html 放一個 hidden 存放新的設定值回傳 server ，程式再從這個欄位讀取新值。 </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/aspnet-google-gadget/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

