Saturday, April 16, 2011

How to solve "Object reference not set to an instance of an object"

Before refer any method or property in an instance of class, make sure the instance is not null


class Class1
{
    public void AnotherExampleMethod()
    {
    }
}
static void Main(string[] args)
{
    var exampleClass = new Class1();    exampleClass.AnotherExampleMethod(); //OK

    var exampleClass1 = null;
exampleClass1.AnotherExampleMethod(); //
//NullReferenceException here. Object reference not set to an instance of an object
}

How to Create HTML5 Website and Page Templates for Visual Studio 2010

http://blog.reybango.com/2010/09/21/how-to-create-html5-website-and-page-templates-for-visual-studio-2010/

How to solve UpdatePanel and Bing map problem

Do not put UpdatePanel and Bing map together... :(

4 ways to solve UpdatePanel and JQuery problem

Solution 1:

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function() {
    // re-bind your jquery events here
});

 Solution 2:
<ContentTemplate>
     <script type="text/javascript">
                    Sys.Application.add_load(BindEvents);
     </script>
 *// Staff*
</ContentTemplate>

Solution 3: 
$(function() {
    $('div._Foo').live("mouseover", function(e) {
        // Do something exciting
    });
});

Solution 4: 
<asp:UpdatePanel runat="server" ID="myUpdatePanel">
    <ContentTemplate>
 
        <script type="text/javascript" language="javascript">
        function pageLoad() {
           $('div._Foo').bind("mouseover", function(e) {
               // Do something exciting
           });
        }
        </script>
 
    </ContentTemplate>
</asp:UpdatePanel>




ASP.NET Base64 Image Encoding via the Data: protocol

ASP.NET Base64 Image Encoding via the Data: protocol

How to add META keywords and Description in ASP.NET

HtmlMeta metaDesc = new HtmlMeta();

metaDesc.Name = "description";

metaDesc.Content = "Tips on roasting coffee at home";
Page.Header.Controls.Add(metaDesc);

HtmlMeta metaKey = new HtmlMeta();
metaKey.Name = "keywords";
metaKey.Content = "roast, coffee, home, tips";
Page.Header.Controls.Add(metaKey);



<meta name="description" content="Tips on roasting coffee at home" />
<meta name="keywords" content="roast, coffee, home, tips" />

Hacking jQuery-Validate in ASP.NET MVC

Hacking jQuery-Validate in ASP.NET MVC - Matt Hamilton