INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Radio button processing

Radio button processing

(OP)
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...">
<html xmlns="http://www.w3.org/1999/xhtml">
<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);
}

}
}

RE: Radio button processing

I am not understanding your question. Your radio button list is on Default.aspx. When you click the OK ,button the page posts back to itself. In the Page_Load or Button_Click event you can then get the value. So I am not understanding what you think will happen or what you want to happen

RE: Radio button processing

(OP)
Ya, I know you can post back to the form page, no troubles there. My question was clearly stated, "Code Behind page". When I post the form, I wanted to display the value of the selected radio button. Anyway, I figured it out.

I added the following to the Button Click event in the "Code Behind Page", and got the result I wanted:

string stTest = Request.Form["RadioButtonList1"].ToString();
Response.Write(stTest);

Works to perfection

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close