radio button don't work with code behind

K

khawar

radio buttons give error messages when programming using
code-behind
If you guys can help you will save my life help help help.

following is the a.aspx file:
<%@ Page Inherits="MyCodeBehind" Src="a.cs" %>
<html><head></head><body>
<form action="a.cs" runat=server>
<asp:RadioButtonList id=RadioButtonList1 runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
</asp:RadioButtonList>
<asp:Button id=Button1 Text="Submit"
onclick="Button1_Click" runat="server"/>
<asp:Label id=Label1 font-name="Verdana" font-size="8pt"
runat="server"/>
</form></body></html>

following is the a.cs file
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public class MyCodeBehind : Page
{
RadioButtonList RadioButtonList1;
Button Button1;
Label label1;
public void Button1_Click(object Source, EventArgs e){
if (RadioButtonList1.SelectedIndex > -1) {
label1.Text =
RadioButtonList1.SelectedIndex.ToString();
}
}
}

following is the error:
Object reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object
reference not set to an instance of an object
NullReferenceException: Object reference not set to an
instance of an object.]
MyCodeBehind.Button1_Click(Object Source, EventArgs e)
+17
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
+108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEve
ntHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent
(IPostBackEventHandler sourceControl, String
eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent
(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top