Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Saturday, October 11, 2014

Asp.net NullReferenceException and how fix it

What is a “NullReferenceException” and how fix it in Asp.net:



The runtime throwing a “NullReferenceException” always means the same thing. You are trying to use a reference to an object which isn't initialized. It means your code used an object reference variable (actual object instance) that was set to null.

When “NullReferenceException” occurs:

When we declare a variable but not initialized the value to declared variable.
Int a; If this case some time it’s possible that here occurs NullReferenceException.

Example of NullReferenceException:

Int a;
If(check1.selected)
{
a=20;
}
Response.wright(a);   //Exception can occur here.

How to prevent by NullReferenceException:

This means the reference points to null, on which you cannot access members.

The simplest case:

String foo = null;
foo.ToUpper();

This will throw a NullReferenceException at the second line, because you can't call the instance method ToUpper() on a string reference pointing to null.

Other Asp.net Example:


Checkboxlist control related old post :

No comments:

Post a Comment