473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

Expand|Select|Wrap|Line Numbers
  1. public static string[] GetArea(string prefixText, int count)
  2. {
  3.     RadioButton rb1 = RadioButton2;
  4.  
  5.         if (rb1.Checked == true)
  6.         {
  7.             //execute some code
  8.            //return something
  9.         }
  10.         else
  11.         {
  12.             //else do this.
  13.            // return something
  14.         }
  15.     }
I am getting error at this line

Expand|Select|Wrap|Line Numbers
  1. if (rb1.Checked == true)
RadioButton2 is defined in my .aspx page

Expand|Select|Wrap|Line Numbers
  1. <asp:RadioButton ID="RadioButton2" name="radios" CssClass="radio-button-style" runat="server" GroupName="list" Text="Chemist" ToolTip="SEARCH " />
Please Help.Thank You.
Jan 11 '16 #1
4 2207
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\Microsoft.NET\Framework\v1.0.3705\gacut il /i C:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll

Copied from this link : https://support.microsoft.com/en-us/kb/810098
Jan 11 '16 #2
Luk3r
300 256MB
You have to use the "new" operator to create a new radio button object.

Example:
Expand|Select|Wrap|Line Numbers
  1. RadioButton rb1 = New RadioButton();
Jan 11 '16 #3
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.
Jan 12 '16 #4
Tried.Still getting the same error:(
Jan 12 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Raymond Cheung | last post by:
On the aspx page, I have the following code <asp:Radiobutton id=heis Text="Yes" Groupname="idiot" checked="true" runat="server" /> &nbsp&nbsp&nbsp <asp:Radiobutton id=heisnot Text="No"...
3
by: Christer | last post by:
Hi all! We're creating an administration for a web application. This includes severeal aspx pages. Our key entity in the web application is "Profile", which can have a certain type. Based on...
5
by: Dan | last post by:
We have a simple site. It's a frameset with two frames a left and a right. The left frame is essentially a list of records from a database (using a server-side repeater control). When you click...
1
by: | last post by:
Hi guys! I am a beginner with aspx (i have some background with .asp). And i am trying tu use a 'code-behind' page in order to execute all transactions in that page and leave as clean as possible...
5
by: Girish | last post by:
hey all, im building a asp.net project in vs.net. Is there a way to have the codebehind files sit in a different folder outside the website folder altogether? example: The aspx files are in...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
2
by: vksundari | last post by:
I am executing a select query in a C# component and populating a ASP Grid in Search.aspx. Now one of the columns in the Grid in Search.aspx is Policy Number(hyper link) Basicallly I want to call a...
0
by: Dan Beanweed | last post by:
Greetings all. I have looked far and wide but found nothing to help me with this. My datagrid has a hidden column with an id number bound to it. Then there is a column of radio buttons. (Then more...
3
by: Iluvatar | last post by:
Hi, last week our project upgraded from vs.net 2005 to vs.net 2008. Our project still uses framework 2.0, because the deployment servers are not 3.x ready yet. Everything so far while migrating...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.