12
Answers

Object reference not set to an instance of an object.

KAJAL TANEJA

KAJAL TANEJA

8y
878
1

Hi i am trying to check whether my RadioButton is checked or not in a method.If checked execute some code else execute another code.

But when i debug it I am getting this error

Object reference not set to an instance of an object
 

I have gone through many links but not able to correct it.

Below is my .aspx.cs code

 
public static string[] GetArea(string prefixText, int count)
{
     RadioButton rb1 = RadioButton2;
         if (rb1.Checked == true)
         {
                 //execute some code
               //return some value;
         }
        else
        {
              //execute some other code
             //return some value;
         }
}
 
RadioButton2 is defined in my .aspx page
<asp:RadioButton ID="RadioButton2" CssClass="radio-button-style" runat="server" GroupName="list" Text="Chemist" ToolTip="SEARCH" />
 
I am getting error at this line
if (rb1.Checked == true)
Please help.Thankyou 
Answers (12)