Friday, January 28, 2011

DependencyProperty in SilverLight/WPF

Unlike usual .Net property, DependencyProperty is defined as static member for a class. The dependencyProperty is not used to store the data as instance members, instead it is used to indicate that the class understands the defined depenency property, so knows how to use this DependencyProperty.

Usually, the class also defines the get/set wrap accessors for the DependencyProperty, they are instance members, since they use the DependencyProperty as key to read and set the data from the hashtable that stores all dependency values.

Note once a DependencyProperty is defined in a class, the value for this property can be set/get to any classes that derived from DependencyObject, not only the class defines it. For example Grid.ColumnProperty in Grid class can be set to a TextField instance. However, only Grid class knows how to apply this property when laying out the TextField. The TextField just stores the value into its DependencyProperty hash table, and never knows what this property really means. In this sense, the DependencyProperty is also called as AttachedProperty.

Jonathan

Sunday, January 2, 2011

adb.exe in Android SDK not installed on Windows Server 2008 (64 bit)

When installing Android SDK to Windows Server 2008 (64 bit), adb.exe does not get installed in platform-tools folder, it seems Windows server 2008 is not a supported platform, although it is unlikely there is any difference between Win Server 2008 (64 bit) and Windows 7 (64 bit) in term of eclipse for android support.

A workaround is copying the whole platform-tools folder from Windows 7 to Windows server 2008. And then set the Android sdk location again from Eclipse Windows->Preference menu, and all function works just fine.

Jonathan

Tuesday, December 28, 2010

Validation of viewstate in web farm

The default ASP.NET settings ensure that viewstate are tamper proof and encrypted. This ensures that any modification of the ViewState either on the client's computer or over the network is detected when the server processes the data.
To provide tamper proof ViewState, the ViewState content is hashed for each response and the hash is compared on subsequent requests. The validation attribute of the machineKey indicates which hashing algorithm to use, and it defaults to SHA1. If the application is installed in a Web farm, it is needed to change the validationKey from the defautl value of AutoGenerate,IsolateApps to a specific manually generated key value
With the default settings shown above, the AutoGenerate setting instructs ASP.NET to generate a random key. The IsolateApps modifier causes ASP.NET to generate a unique key for each application on your server by using the application ID of each application.
The default value is correct for a single server deployment. You will need to change the default settings if your application is deployed in a Web farm. In a Web farm, you must manually generate the validationKey value and make sure that it is the same on all servers in the farm.

Sunday, December 26, 2010

Setting NavigateUrl property will not set the menu item as selected

If NavigateUrl is set for a menu item, when users select this menu item, the menu item will not be set as selected menu item. The only exception is when the menu item data are populated from site map. In all other case, ASP.Net will not set the selected menu item for the application.
The workaround is getting the aspx file name from request's physical path, and then matching the file name to the corresponding menu item, and then programatically set the matched menu item to be selected.
The issue can be repeated by setting a static menu collection in master page, and then navigate to some content page by click a menu item.

Jonathan

Wednesday, December 22, 2010

Postback with dynamically created controls

One of the main challenges with working with dynamically added controls is that these controls must be programmatically added on each postback. That is, you can't just load these controls on the first page load, and then not reload them on subsequent postbacks. Failure to explicitly add the controls on each postback will cause the controls to literally disappear on postbacks. To further complicate things, the point in the page's lifecycle when dynamic controls are added is important if you want to maintain changed values across postback. For example, imagine you had a Web page that displayed a series of input form fields based on the user visiting the page. The idea here would be to allow the visitor enter some values into these custom input form fields, and then submit the form, having the data saved. If the dynamic Web controls are not added at the correct time in the page's lifecycle, the values entered by the visitor will be lost on postback.

Jonathan

Monday, December 20, 2010

MasterPage and Ajax toolkit

If a content page wants to add a control from ASP.Net Ajax toolkit, like the tab control, it can not simply add the control in it. Doing so will causes an error of resource can not be found...
Before adding an Ajax control in content page, the master page must add the script manager that will be shared by all content pages.
In addition, a content page can also include its own javascrpt file by using script manager proxy
Note that both master page and content page need to @register ajaxcontroltoolkit assmemby.

Jonathan

Tuesday, December 14, 2010

Global resource for ASP.Net localization

When adding localization resource in global resource folder, the region-language name must match the predefined ones. Otherwise, when building the project, an error will happen saying "Error 1: the namespace ??? already contains an definition of ???".
For example, adding a resource of "resource.cn.resx" in the project will cause the error. Changing the name into "resource.zh-CN.resx" will fix it.

Jonathan