Wednesday, January 12, 2011

How to deal with "The underlying provider failed on Open" in Entity Framework

Please use using statement to include your access to Object Context:


            using (var ctx = new Entities())
            {
                ....
            }
Provides a convenient syntax that ensures the correct use of IDisposable objects.

How to set auto-width for dropdownlist in IE by JQuery

<select onmousedown="if($.browser.msie){this.style.position='absolute';this.style.width='auto'}" onblur="this.style.position='';this.style.width=''">

Tuesday, January 11, 2011

How to change master page on the fly in ASP.NET

In web form page, add: 
protected void Page_PreInit(object sender, EventArgs e) 

{ 

    this.Page.MasterPageFile = "~/name.master";

}

How to get current page name in master page?

public string GetCurrentPageName() 
{ 
    string Path = System.Web.HttpContext.Current.Request.Url.AbsolutePath; 
    System.IO.FileInfo fInfo = new System.IO.FileInfo(Path); 
    return fInfo.Name; 
}