Hi
I've got code that is working properly on one page. But I want to separate each RadioButton group to each .aspx page.
Yes, master pages can help, but I'm newbie in programming
I generated master page and 3 "content" aspx pages for free RadioButton groups each. My idea is to managing that 3 pages with radiobuttons + button for "submit" from one codefile "MasterMain.master.cs". Does it possible?
That is my code:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
public partial class MainLayOut : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "The Time of Server is: " + DateTime.Now.TimeOfDay;
}
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 Label message;
protected Label message2;
protected Label Label5;
int X1;
int X2;
int X3;
int i;
int rezultat;
int vOtg;
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)
{
vOtg = (int)ViewState["vOtg"];
}
}
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]))
{
rezultat += 1;
}
}
message2.Text = "Result"+ " " + rezultat + " " + "points";
}
}
That is compilation error:
a1.CheckedChanged += selectionHandler1;<--Object reference not set to an instance of an object.(NullReferenceException)
I've got code that is working properly on one page. But I want to separate each RadioButton group to each .aspx page.
Yes, master pages can help, but I'm newbie in programming
I generated master page and 3 "content" aspx pages for free RadioButton groups each. My idea is to managing that 3 pages with radiobuttons + button for "submit" from one codefile "MasterMain.master.cs". Does it possible?
That is my code:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
public partial class MainLayOut : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "The Time of Server is: " + DateTime.Now.TimeOfDay;
}
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 Label message;
protected Label message2;
protected Label Label5;
int X1;
int X2;
int X3;
int i;
int rezultat;
int vOtg;
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)
{
vOtg = (int)ViewState["vOtg"];
}
}
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]))
{
rezultat += 1;
}
}
message2.Text = "Result"+ " " + rezultat + " " + "points";
}
}
That is compilation error:
a1.CheckedChanged += selectionHandler1;<--Object reference not set to an instance of an object.(NullReferenceException)