radio button don't work with code behind

Discussion in 'ASP .Net' started by khawar, Aug 7, 2003.

  1. khawar

    khawar Guest

    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
    khawar, Aug 7, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    569
    Alphonse Giambrone
    Jun 28, 2003
  2. psb
    Replies:
    2
    Views:
    17,014
    Achintya Jha
    Sep 22, 2004
  3. Scott D Johnson
    Replies:
    1
    Views:
    1,049
    Scott D Johnson
    Sep 27, 2006
  4. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    465
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  5. Hiten
    Replies:
    1
    Views:
    609
    Vidar Petursson
    May 26, 2004
Loading...

Share This Page