我正在尝试将表单值传递到将使用类来执行存储过程的页面。为了从表单到页面获取值,我将所有数据放入哈希表中。进入哈希表后,我将其放入会话中。挑战在于数据没有进入会话。
这是将表单放入哈希表和会话的代码。
public partial class addRegistration : System.Web.UI.Page
{
//variables for transaction amounts
public int type = 4;
public string acsamt = "0";
public int acscontribution = 0;
protected void Page_Load(object sender, EventArgs e)
{
object sessionObject = Session["registration"];
}
protected void On_Click(object sender, EventArgs e)
{
Hashtable htReg = new Hashtable();
htReg.Add("sponsor", sponsorName.Text);
htReg.Add("salutation", salutation.SelectedValue.ToString());
htReg.Add("contact_fname", contactPerson_fname.Text);
htReg.Add("contact_lname", contactPerson_lname.Text);
htReg.Add("street", street.Text);
htReg.Add("city", city.Text);
htReg.Add("statecode", statecode.SelectedValue.ToString());
htReg.Add("zip", zip.Text);
htReg.Add("email", custemail.Text);
htReg.Add("phone", phone.Text);
htReg.Add("invoiceNumber", invoiceNum.Text);
htReg.Add("regType", type);
htReg.Add("acsamount", acsamt);
htReg.Add("acscontribution", acscontribution);
htReg.Add("player1", p1_name.Text);
htReg.Add("player2", p2_name.Text);
htReg.Add("player3", p3_name.Text);
htReg.Add("player4", p4_name.Text);
Session["registration"] = htReg;
}
}
以下是我从会话中获取数据的另一面。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Hashtable htReg = new Hashtable();
htReg = (Hashtable)Session["registration"];
dbAction db = new dbAction();
db.AddRegistration(htReg);
}
}
使用会话/哈希表是否无法实现此目的?