<?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>I&#039;m CaLendarW Blog &#187; asp.net</title>
	<atom:link href="http://wongkalun.idv.hk/tag/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://wongkalun.idv.hk</link>
	<description>任何時間，都要用內心既一點光，照亮世界</description>
	<lastBuildDate>Tue, 17 Aug 2010 15:00:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Default Button and Default Focus in Master Page.</title>
		<link>http://wongkalun.idv.hk/2008/01/17/default-button-and-default-focus-in-master-page/</link>
		<comments>http://wongkalun.idv.hk/2008/01/17/default-button-and-default-focus-in-master-page/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 02:20:59 +0000</pubDate>
		<dc:creator>calendarw</dc:creator>
				<category><![CDATA[coding snippet]]></category>
		<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://wongkalun.idv.hk/?p=22</guid>
		<description><![CDATA[自從轉左用 ASP.net 2.0 既 Master Page 之後, 個 form 出左出面, 所以以為無得用 Form Set Default Focus 同 Default Button, 阿敏今日 send 左個 site 比我, 入面考用 Page.Form 黎 Set Default Focus 同 Default Button, 要注意既係用 Default Button 既 UniqueID 同埋 Default Focus 既 ClientID Page.Form.DefaultFocus = TextBox1.ClientID Page.Form.DefaultButton = Button1.UniqueID dtsv.dtse_post_22_permalink = 'http://wongkalun.idv.hk/2008/01/17/default-button-and-default-focus-in-master-page/'; dtsv.dtse_post_22_title = 'Default Button [...]]]></description>
			<content:encoded><![CDATA[<p>自從轉左用 ASP.net 2.0 既 Master Page 之後, 個 form 出左出面, 所以以為無得用 Form Set Default Focus 同 Default Button, 阿敏今日 send 左個 <a href="http://imar.spaanjaars.com/QuickDocId.aspx?QUICKDOC=374">site</a> 比我, 入面考用 Page.Form 黎 Set Default Focus 同 Default Button, 要注意既係用 Default Button 既 UniqueID 同埋 Default Focus 既 ClientID</p>
<pre class="brush: csharp;">Page.Form.DefaultFocus = TextBox1.ClientID
Page.Form.DefaultButton = Button1.UniqueID</pre>



		<!-- Added by WP-DragToShare-eXtended Plugin -->
		<script type="text/javascript">
			dtsv.dtse_post_22_permalink = 'http://wongkalun.idv.hk/2008/01/17/default-button-and-default-focus-in-master-page/';
			dtsv.dtse_post_22_title = 'Default Button and Default Focus in Master Page.';
		</script>
		<!-- End of WP-DragToShare-eXtended Plugin -->]]></content:encoded>
			<wfw:commentRss>http://wongkalun.idv.hk/2008/01/17/default-button-and-default-focus-in-master-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding ListItems don&#8217;t work with CheckboxList,RadiobuttonList etc.</title>
		<link>http://wongkalun.idv.hk/2007/10/09/adding-listitems-dont-work-with-checkboxlistradiobuttonlist-etc/</link>
		<comments>http://wongkalun.idv.hk/2007/10/09/adding-listitems-dont-work-with-checkboxlistradiobuttonlist-etc/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 08:19:18 +0000</pubDate>
		<dc:creator>calendarw</dc:creator>
				<category><![CDATA[error handling]]></category>
		<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://wongkalun.idv.hk/?p=14</guid>
		<description><![CDATA[This is a bug of asp.net in 1.0 and 1.1, you may need to use HtmlInputRadioButton instead of RadioButtonList or HtmlSelect instead of DropDownList Microsoft Article: 309338 dtsv.dtse_post_14_permalink = 'http://wongkalun.idv.hk/2007/10/09/adding-listitems-dont-work-with-checkboxlistradiobuttonlist-etc/'; dtsv.dtse_post_14_title = 'Adding ListItems don’t work with CheckboxList,RadiobuttonList etc.';]]></description>
			<content:encoded><![CDATA[<p>This is a bug of asp.net in 1.0 and 1.1, you may need to use <strong>HtmlInputRadioButton</strong> instead of <strong>RadioButtonList</strong> or <strong>HtmlSelect</strong> instead of <strong>DropDownList</strong></p>
<p>Microsoft Article: <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q309338" title="The Attributes property of a ListItem control only works within an HtmlSelect control" target="_blank">309338</a></p>



		<!-- Added by WP-DragToShare-eXtended Plugin -->
		<script type="text/javascript">
			dtsv.dtse_post_14_permalink = 'http://wongkalun.idv.hk/2007/10/09/adding-listitems-dont-work-with-checkboxlistradiobuttonlist-etc/';
			dtsv.dtse_post_14_title = 'Adding ListItems don’t work with CheckboxList,RadiobuttonList etc.';
		</script>
		<!-- End of WP-DragToShare-eXtended Plugin -->]]></content:encoded>
			<wfw:commentRss>http://wongkalun.idv.hk/2007/10/09/adding-listitems-dont-work-with-checkboxlistradiobuttonlist-etc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET Event Validation</title>
		<link>http://wongkalun.idv.hk/2007/08/20/aspnet-event-validation/</link>
		<comments>http://wongkalun.idv.hk/2007/08/20/aspnet-event-validation/#comments</comments>
		<pubDate>Mon, 20 Aug 2007 15:36:37 +0000</pubDate>
		<dc:creator>calendarw</dc:creator>
				<category><![CDATA[error handling]]></category>
		<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://wongkalun.idv.hk/?p=6</guid>
		<description><![CDATA[[http://asp.net ASP.net] 2.0 添加了 event validation 的功能, 用來檢查張 form 的 variable, 如果張 form 係一開始時無將 possible variable encode 入個 session 度, 就會 throw exception: Invalid postback or callback argument. Event validation is enabled using &#60;pages enableEventValidation=&#8221;true&#8221;/&#62; in configuration or &#60;%@ Page EnableEventValidation=&#8221;true&#8221; %&#62; in a page. For security purposes, this feature verifies that arguments to postback [...]]]></description>
			<content:encoded><![CDATA[<p>[http://asp.net ASP.net] 2.0 添加了 event validation 的功能, 用來檢查張 form 的 variable, 如果張 form 係一開始時無將 possible variable encode 入個 session 度, 就會 throw exception:</p>
<blockquote><p>Invalid postback or callback argument.  Event validation is enabled using &lt;pages enableEventValidation=&#8221;true&#8221;/&gt; in configuration or &lt;%@ Page EnableEventValidation=&#8221;true&#8221; %&gt; in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.</p></blockquote>
<p><span id="more-6"></span><br />
呢個係防止 [http://weblogs.asp.net/bleroy/archive/2004/08/18/216861.aspx injection attack] 既設計, 但是同時有部份 client script 也會出錯, 例如在 asp.net render DropDownList 時,會record 晒所有有可能既 value, 儲係個 page 度</p>
<p>這個過程發生在control的Render()方法中<br />
當頁面postback時,ASP.NET會根據這個隱藏值檢查postback values,如果找不到對應信息,就會throw exception. 所以所有有關 client script 改動 list control 既動作就會有影響</p>
<p>解決方法<br />
1. 禁止這個功能, 但同時會失去一些安全保障:<br />
//—-通過web.config</p>
<pre lang="xml"></pre>
<p>//—-針對某個page</p>
<pre lang="xml">&lt;%@ Page EnableEventValidation="false" … %&gt;</pre>
<p>2.Register For Event Validation<br />
其原理就是讓asp.net記錄這個postback value.<br />
RegisterForEventValidation必須在render() 內使用.</p>
<pre lang="csharp">protected override void Render(HtmlTextWriter writer)
{
	ClientScript.RegisterForEventValidation(_recipeList.UniqueID,"4");
	// 4 係其中一個 possible value
	base.Render(writer);
}</pre>
<p>如果我們自己寫了一個control,需要使用validate events功能,就需要使用SupportsEventValidation attribute,</p>
<pre lang="csharp">[SupportsEventValidation]
public class DynamicDropDownList : DropDownList
{
	protected override void Render(System.Web.UI.HtmlTextWriter writer)
	{
		Page.ClientScript.RegisterForEventValidation(this.UniqueID, "4");
		// 4 係其中一個 possible value, 如果多過一個就要每個 register 一次
		base.Render(writer);
	}
}</pre>
<p>目前,asp.net還不能單獨禁止某個control的validate events功能.</p>



		<!-- Added by WP-DragToShare-eXtended Plugin -->
		<script type="text/javascript">
			dtsv.dtse_post_6_permalink = 'http://wongkalun.idv.hk/2007/08/20/aspnet-event-validation/';
			dtsv.dtse_post_6_title = 'ASP.NET Event Validation';
		</script>
		<!-- End of WP-DragToShare-eXtended Plugin -->]]></content:encoded>
			<wfw:commentRss>http://wongkalun.idv.hk/2007/08/20/aspnet-event-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
