Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

one .cs file for some asp pages, how?

Status
Not open for further replies.

neomax

Programmer
Jul 1, 2006
29
BG
Hello, I've got a code for 3 groups radiobuttons and one button for submit. The form is placed on one .asp page and everything working properly. My question is how to separate each group radiobuttons for each page (3 groups makes 3 pages)and in last page place a "submit" button?

that is my code for one page, it's working:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;

public class ButtonTest : Page
{
protected RadioButton a1;
protected RadioButton a2;
protected RadioButton a3;
protected RadioButton b1;
protected RadioButton b2;
protected RadioButton b3;
protected RadioButton c1;
protected RadioButton c2;
protected RadioButton c3;
protected Button Button4;
protected HyperLink HyperLink1;

protected Label message;
protected Label message2;
protected Label Label5;

int X1;
int X2;
int X3;
int i;
int rezult;
int vOtgovor;

public void Page_Init(Object sender, EventArgs e)
{
EventHandler selectionHandler1 =
new EventHandler(RadioChangeQuestion1);
EventHandler selectionHandler2 =
new EventHandler(RadioChangeQuestion2);
EventHandler selectionHandler3 =
new EventHandler(RadioChangeQuestion3);
EventHandler selectionHandler4 =
new EventHandler(button1_Click);



a1.CheckedChanged += selectionHandler1;
a2.CheckedChanged += selectionHandler1;
a3.CheckedChanged += selectionHandler1;
b1.CheckedChanged += selectionHandler2;
b2.CheckedChanged += selectionHandler2;
b3.CheckedChanged += selectionHandler2;
c1.CheckedChanged += selectionHandler3;
c2.CheckedChanged += selectionHandler3;
c3.CheckedChanged += selectionHandler3;
Button4.Click += selectionHandler4;


if (ViewState["X1"] != null)
{
X1 = (int)ViewState["X1"];
}
if (ViewState["X2"] != null)
{
X2 = (int)ViewState["X2"];
}
if (ViewState["X3"] != null)
{
X3 = (int)ViewState["X3"];
}
if (ViewState["vOtgovor"] != null)
{
vOtgovor = (int)ViewState["vOtgovor"];
}
}

public void RadioChangeQuestion1(Object sender, EventArgs e)
{
RadioButton checkedButton = null;
if (a1.Checked)
{
checkedButton= a1;
}
else if (a2.Checked)
{
checkedButton = a2;
}
else if (a3.Checked)
{
checkedButton = a3;
}
if (checkedButton != null)
{
string X1 = checkedButton.Text;
ViewState["X1"] = X1;
}
}

public void RadioChangeQuestion2(Object sender, EventArgs e)
{
RadioButton checkedButton = null;
if (b1.Checked)
{
checkedButton = b1;
}
else if (b2.Checked)
{
checkedButton = b2;
}
else if (b3.Checked)
{
checkedButton = b3;
}
if (checkedButton != null)
{
string X2 = checkedButton.Text;
ViewState["X2"] = X2;
}
}


protected void RadioChangeQuestion3(Object sender, EventArgs e)
{
RadioButton checkedButton = null;
if (c1.Checked)
{
checkedButton = c1;
}
else if (c2.Checked)
{
checkedButton = c2;
}
else if (c3.Checked)
{
checkedButton = c3;
}
if (checkedButton != null)
{
string X3 = checkedButton.Text;
ViewState["X3"] = X3;
}
}

static string CONNECTION_STRING = "server=(local); database=tests; trusted_connection=yes;";

private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection(CONNECTION_STRING);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM dbo.test";
SqlDataAdapter da = new SqlDataAdapter((cmd));
DataSet ds = new DataSet();
da.Fill(ds);

X1 = Convert.ToInt32(ViewState["X1"]);
X2 = Convert.ToInt32(ViewState["X2"]);
X3 = Convert.ToInt32(ViewState["X3"]);
int[] otgovor = new int[3] { X1, X2, X3 };

for (int i = 0; i < 3; i++)
{
if (otgovor == ((int) ds.Tables[0].Rows[4]))
{
rezult+=1;
}
}
message2.Text = + " " + rezult;
}

Thaks:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top