I would like to add a Radio Button control within my asp.net Form. When the form is submitted, I would like the value of the Radio Control go to the "Code Behind page (Default.aspx.cs)". Using C#, I want the processing to occur there, and not within the page where the Form is (Default.aspx). Any suggestions? Bellow is a basic layout of the form with a working "Code behind page with existing Form controls"
Thanks in advance!
Default.aspx
<%@ Page
Language = "C#"
AutoEventWireup = "false"
Inherits = "RadioButton.Default"
ValidateRequest = "false"
EnableSessionState = "false"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<title>RadioButton</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
<meta http-equiv="PRAGMA" content="NO-CACHE" />
</head>
<body>
<form id="Form1" method="post" runat="server">
<!-- Site Code goes here! -->
<table>
<tr>
<td valign="top">Name:</td>
<td>
<input id="_Input_Name" runat="server" />
</td>
</tr>
<tr>
<td valign="top">Options:</td>
<td>
<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem Selected="True">Item1</asp:ListItem>
<asp:ListItem>Item2</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<input id="_Button_Ok" type="submit" value="Ok" runat="server" />
</td>
</tr>
</table>
</form>
</body>
</html>
-----------------------------------------------------------
Default.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace RadioButton
{
public class Default : Page
{
//Form Control Constructors
protected HtmlInputButton _Button_Ok;
protected HtmlInputText _Input_Name;
//PageInit
protected void PageInit(object sender, EventArgs e)
{
}
//PageExit
protected void PageExit(object sender, EventArgs e)
{
}
//Page_Load
private void Page_Load(object sender, EventArgs e)
{
//Post Back
if(IsPostBack)
{
}
}
//Button Click Event
protected void Click_Button_Ok(object sender, EventArgs e)
{
Response.Write( _Button_Ok.Value + " was clicked!<br>");
}
//Input Change Event
protected void Changed_Input_Name(object sender, EventArgs e)
{
Response.Write( _Input_Name.Value + " has changed!<br>");
}
//region Initialize Component
protected override void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
//InitializeComponent Method
private void InitializeComponent()
{
this.Load += new System.EventHandler(Page_Load);
this.Init += new System.EventHandler(PageInit);
this.Unload += new System.EventHandler(PageExit);
_Button_Ok.ServerClick += new EventHandler(Click_Button_Ok);
_Input_Name.ServerChange += new EventHandler(Changed_Input_Name);
}
}
}
Thanks in advance!
Default.aspx
<%@ Page
Language = "C#"
AutoEventWireup = "false"
Inherits = "RadioButton.Default"
ValidateRequest = "false"
EnableSessionState = "false"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<title>RadioButton</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
<meta http-equiv="PRAGMA" content="NO-CACHE" />
</head>
<body>
<form id="Form1" method="post" runat="server">
<!-- Site Code goes here! -->
<table>
<tr>
<td valign="top">Name:</td>
<td>
<input id="_Input_Name" runat="server" />
</td>
</tr>
<tr>
<td valign="top">Options:</td>
<td>
<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem Selected="True">Item1</asp:ListItem>
<asp:ListItem>Item2</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<input id="_Button_Ok" type="submit" value="Ok" runat="server" />
</td>
</tr>
</table>
</form>
</body>
</html>
-----------------------------------------------------------
Default.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace RadioButton
{
public class Default : Page
{
//Form Control Constructors
protected HtmlInputButton _Button_Ok;
protected HtmlInputText _Input_Name;
//PageInit
protected void PageInit(object sender, EventArgs e)
{
}
//PageExit
protected void PageExit(object sender, EventArgs e)
{
}
//Page_Load
private void Page_Load(object sender, EventArgs e)
{
//Post Back
if(IsPostBack)
{
}
}
//Button Click Event
protected void Click_Button_Ok(object sender, EventArgs e)
{
Response.Write( _Button_Ok.Value + " was clicked!<br>");
}
//Input Change Event
protected void Changed_Input_Name(object sender, EventArgs e)
{
Response.Write( _Input_Name.Value + " has changed!<br>");
}
//region Initialize Component
protected override void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
//InitializeComponent Method
private void InitializeComponent()
{
this.Load += new System.EventHandler(Page_Load);
this.Init += new System.EventHandler(PageInit);
this.Unload += new System.EventHandler(PageExit);
_Button_Ok.ServerClick += new EventHandler(Click_Button_Ok);
_Input_Name.ServerChange += new EventHandler(Changed_Input_Name);
}
}
}