Tuesday, February 26, 2008

Put ConfigSections on the top

Today, I just find the problem why my code can not detect my custom config sections. because I put config sections after <AppSettings> -)

Use Ctrl + . to Resolve in VS2008

Use Ctrl + . when you notice red underscore to Select a Resolve solution for you

Wednesday, February 20, 2008

Live Writer for Coder

These are plugins which will help me to write better content 

  • CodeSnippetSetup.msi - Wrap your code into a container
  • vspaste.msi - Copy paste from Visual studio
public static class HelloClass
{
public static void HelloWorld()
{
//Hi I just found this plugin makes our live easier for writing a blog...
}
}

Wednesday, February 13, 2008

Improve your AJAX Performance

Just quick note what I just got this morning from RDN with Damian.

  1. Disable compilation debug mode into false compilation debug="false"
    - This will decrease the javascript code downloaded from ajax frameworks

  2. If you don't use update panel, just using control toolkit,
    disable partial rendering on Script Manager
    EnablePartialRendering="false"
    - This improve the process for common postback, without checking update panel

  3. Try to saperate update panel as small as possible and put UpdateMode="Conditional".
    this will not send back other update panel content on partial rendering.
    By Default it sets to Always means it will send the content even not rendered.

  4. For using Not friendly AJAX control such as Telerik, Reporting Services Viewer which can not use update panel to do partial postback.
    You may put it into partial postback but add an attribute in Update Panel ChildrenAsTriggers="false". This will perform partial postback but not update your panel.

    so to update another panel you can do manually __doPostback(%= ID%, ...) or just handle it in the control.

    The ChildrenAsTriggers property determines whether postbacks from a child ontrol in an UpdatePanel result in its contents being refreshed. By default, this property is set to True and can be set to False only when the UpdateMode is set to conditional. Attempting to do so without this condition results in an InvalidOperationException being thrown by the ScriptManager during the page’s PreRender event.

  5. In my experience I also turn off EnableViewState and It works fine, but I don't know if this improve the performance

And Don't forget to use Web Development Helper for IE , but before that you may need to install IE Developer tool
http://msmvps.com/blogs/paulomorgado/archive/2007/02/18/developer-tools-for-internet-explorer.aspx

Tuesday, February 12, 2008

KeyValueConfigurationElement VS NameValueConfigurationElement

After checking on the description form MSDN, http://msdn2.microsoft.com/en-us/library/system.configuration.namevalueconfigurationelement(VS.80).aspx

It is written that
"
There is a difference between the NameValueConfigurationElement class and KeyValueConfigurationElement class. The NameValueConfigurationElement class does not require the first string to be unique, whereas KeyValueConfigurationElement class requires the first string to be a key, and therefore unique in the collection.
"

However when I try to test it, it seems that
  1. NameValue also can not display duplicate Names in the collection moreover if the name is the same but the value is different , it will throw an error message which says that name has already has the value.
  2. On the other hand KeyPair, also can not have duplicate keys but if there is duplicate key but different values, it will be override with the last values. There is no error message return.
  3. KeyPair collection will be sorted , I guess it similar with Hashtable collection but NameValue is not sorted.
  4. KeyPair is case sensitive so Key1 and key1 will be consider the same key
    but Namevalue is incase sensitive Name1 and name1 will be consider different name

For solving this problem, I have build my custom collection - can be downloaded at
http://kkurni.googlepages.com/KKurni.CustomConfigurationElementCol.rar

IConfigurationSectionHandler is deprecated on .NET 2.0

I just heard a bad news while reading MCTS Book and MSDN.

It said that IConfugurationSectionHandler is deprecated on .Net 2.0.

We need to inherits from ConfigurationSection instead of implementing IConfigurationSectionHandler.

Somehow it is easier using ConfigurationSection but it is less customization.
  1. We can not have CDATA or text Element anymore. All value need to be placed on attribute.
    Otherwise it will throw this exception
    "The configuration section cannot contain a CDATA or text element."

    If implementing IConfigurationSectionHandler we can easily using XmlElement Declaration . [XmlElement("ElementName")]

  2. for multiple element values , We need to write ConfigurationElementCollection.

    public class ValueCollection : ConfigurationElementCollection
    {
    protected override ConfigurationElement CreateNewElement()
    {
    return new ValueElement();
    }

    protected override object GetElementKey(ConfigurationElement element)
    {
    return ((ValueElement)element).Value;
    }
    }

    public class ValueElement : ConfigurationElement
    {
    [ConfigurationProperty("value")]
    public string Value
    {
    get { return (String)this["value"]; }
    set { this["value"] = value; }
    }
    }

    [ConfigurationProperty("domains")]
    public ValueCollection Domains
    {
    get { return (ValueCollection)this["domains"]; }
    }

    Or you can use default configuration collection such as NameValueConfigurationCollection or KeyValueConfigurationCollection


    But If using IConfigurationSectionHandler we can just use XmlElementAttribute
    [XmlElement("ExtractColumn")]
    public ExtractColumn[] ExtractColumns;

====================
However The nice thing of using ConfigurationSection is
  1. Standard .Net Configuration
  2. Easier to validate and better error Messages
    [ConfigurationProperty("myAttrib1", DefaultValue = "test", IsRequired = true)]
    [StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]

Sunday, February 10, 2008

MVC Framework for ASP.NET is coming

From my previous blog, I just read that Microsoft will provide MVC Framework for AsP.Net Developer.

Here is the good link for MVC Framework
http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx