2008年3月28日 星期五

Using Nullable Types

http://msdn2.microsoft.com/en-us/library/2cf62fcy(VS.80).aspx
Examples of Nullable Types

Any value type may be used as the basis for a nullable type. For example:

int? i = 10;
double? d1 = 3.14;
bool? flag = null;
char? letter = 'a';
int?[] arr = new int?[10];

2008年3月26日 星期三

如何取得Gridview 隱藏欄位的值

在某些時候,我們會想利用Gridview的欄位來放Postback後要用到的資料,但又不想讓這些欄位顯示出來,這時候你可以在 GridView1_RowCreated 這個event,將這些欄位的visible 設成 false,如此在 Postback 時就可以取得這些欄位的值,範例如下:

if ((e.Row.RowType == DataControlRowType.Header e.Row.RowType == DataControlRowType.DataRow) && e.Row.Cells.Count>11)
{
e.Row.Cells[8].Visible = false;
e.Row.Cells[9].Visible = false;
e.Row.Cells[10].Visible = false;
e.Row.Cells[11].Visible = false;
}

  1. 注意:不可以在Design time時將這些欄位的Visible設成false,因為這樣你會取得空值。
  2. asp.net會將這些欄位值放在viewstate內,所以如果有些資料是不能給User看到的,就不適合這樣作,如果一定要,那你就必須將viewstate 加密。

asp.net viewstat decoder

http://www.pluralsight.com/tools.aspx

ViewState Decoder (2.2)

Fritz OnionTool to decode the ViewState in ASP.NET 2.0 pages. This version supports display of control state as well as view state. Screenshot

ViewState Decoder (1.1)

Fritz OnionTool to decode the ViewState in ASP.NET pages compatible with version 1.1 of ASP.NET Screenshot

http://blogs.msdn.com/rextang/archive/2007/05/25/2868250.aspx

2008年3月20日 星期四

asp.net forms authentication Web.Config 範例

如果某一個aspx網頁不需要驗證就可以存取,可以在web.config 加上Location 這個標籤

<configuration>
<system.web>
<authentication mode="Forms" >
<forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
</forms>
<
/authentication>
<!-- This section denies access to all files in this application except for those that you have not explicitly specified by using another setting. -->
<authorization>
<deny users="?" />
</authorization>
<
/system.web>
<!-- This section gives the unauthenticated user access to the Default1.aspx page only. It is located in the same folder as this configuration file. -->
<location path="default1.aspx">
<system.web>
<authorization>
<allow users ="*" />
</authorization>
<
/system.web>
</location>
<!-- This section gives the unauthenticated user access to all of the files that are stored in the Subdir1 folder. -->
<location path="subdir1">
<system.web>
<authorization>
<allow users ="*"
/>
</authorization>
<
/system.web>
</location>
<
/configuration>