Sunday, January 15, 2012

Two ASP.Net Tips

I will be on vacation to China and be back on Jan 15, 2012. Since the Blogger is not accessible from China, I have to schedule my blog so that I will keep my promise to write at least one blog per week. This blog is a scheduled post.

This is note on two tips I found in ASP.Net.

Bind Field with Object Method

It is very common to bind a field to an object's property value. However, I find out one case that I prefer to bind a field with the object's method. The advantage of binding to a method is that I can pass parameter values in. I found a solution from SO.

Here is my example:

Visible='<%#((MyData) Container.DataItem).RawValueAvailable(1) %>'
ErrorMessage="Value cannot be empty">*

I need to add required validation control with a condition if there is value for the bound object.  The above example sets Visible with the method "RawValueAvailable(..) of the bound object of MyData.  It works great.

Set Login Timeout

By default ASP.Net authentication has a timeout of 30 minutes. This timeout looks like that it can be customized. I found an answer from SO. Here is an example:

  <sessionStatetimeout="60"  />

Setting the forms timeout to something less than the session timeout can give the user a window in which to log back in without losing any session data. However, I think that client side cached data will be gone if redirect is called. For example, if a user enters several data into a data grid view, the changed data may be lost if login timeout is passed. There may be a way to provide warning for saving data by using Javascripts.