How to check whether the radiobutton is checked or not in a method in code behind fil

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KajalTaneja
    New Member
    • Jan 2016
    • 3

    How to check whether the radiobutton is checked or not in a method in code behind fil

    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

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

    Below is my .aspx.cs code

    Code:
    public static string[] GetArea(string prefixText, int count)
    {
        RadioButton rb1 = RadioButton2;
    
            if (rb1.Checked == true)
            {
                //execute some code
               //return something
            }
            else
            {
                //else do this.
               // return something
            }
        }
    I am getting error at this line

    Code:
    if (rb1.Checked == true)
    RadioButton2 is defined in my .aspx page

    Code:
    <asp:RadioButton ID="RadioButton2" name="radios" CssClass="radio-button-style" runat="server" GroupName="list" Text="Chemist" ToolTip="SEARCH " />
    Please Help.Thank You.
  • WebBaniya
    New Member
    • Jan 2016
    • 1

    #2
    Try if this works.

    To resolve this problem, register the Adodb.dll file in the global assembly cache (GAC). On a computer where only the .NET Framework is installed, the file Gacutil.exe does not exist.. Either obtain the gacutil file by installing Microsoft .NET Framework SDK, or create a Visual Studio.NET setup project that uses the installer to install the correct components.

    To register Adodb.dll in the GAC, follow these steps:
    Click Start and then click Run.
    In the Run dialog box, type the following command, and then click OK:
    C:\WINDOWS\Micr osoft.NET\Frame work\v1.0.3705\ gacutil /i C:\Program Files\Microsoft .NET\Primary Interop Assemblies\adod b.dll

    Copied from this link : https://support.microsoft.com/en-us/kb/810098

    Comment

    • Luk3r
      Contributor
      • Jan 2014
      • 300

      #3
      You have to use the "new" operator to create a new radio button object.

      Example:
      Code:
      RadioButton rb1 = New RadioButton();

      Comment

      • KajalTaneja
        New Member
        • Jan 2016
        • 3

        #4
        Sir when i am creating a new object then it directly executes the else's code no matter whether my radiobutton is checked or not.

        Comment

        • KajalTaneja
          New Member
          • Jan 2016
          • 3

          #5
          Tried.Still getting the same error:(

          Comment

          Working...