0

我尝试设置会话值,但每次我想显示用户在上一页中输入的文本时,它都会返回 null

我有三个页面订阅者详细信息,包裹选择和银行详细信息,所有三个页面相互跟随,并且用户已经用他/她想要的信息填写了所有页面并单击下一步,他们被定向到显示他们输入的所有信息的页面.

我似乎也看不出我做错了什么?

订阅者详细信息.aspx

protected void Button1_Click(object sender, EventArgs e)
{
    string FullName = txtFullName.Text;
    string CompanyName = txtCompanyName.Text;
    string Vat = txtVAT.Text;
    string ContactNumber = txtContactNumber.Text;
    string Fax = txtFax.Text;
    string District = txtDistrict.Text;
    string Street = txtStreet.Text;
    string City = txtCity.Text;
    string Code = txtPostal.Text;
    string Trading = txtTrading.Text;
    string Id = txtID.Text;
    string ContactPerson = txtContactPerson.Text;
    string Email = txtEmail.Text;

        Session["FullName"] = FullName;
        Session["CompanyName"] = CompanyName;
        Session["VAT"] = Vat;
        Session["ContactNumber"] = ContactNumber;
        Session["Fax"] = Fax;
        Session["District"] = District;
        Session["City"] = City;
        Session["Street"] = Street;
        Session["Code"] = Code;
        Session["Trading"] = Trading;
        Session["ID"] = txtID.Text;
        Session["ContactPerson"] = ContactPerson;
        Session["Email"] = Email;

}

最终的.aspx

protected void Page_Load(object sender, EventArgs e)
{
    if (string.IsNullOrEmpty((string)Session["Fullname"]))
    {
        lblFullName.Text = "N/A";
    }
    else
    {
        lblFullName.Text = Session["FullName"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["CompanyName"]))
    {
        lblCompanyName.Text = "N/A";
    }
    else
    {
        lblCompanyName.Text = Session["CompanyName"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["VAT"]))
    {
        lblVat.Text = "N/A";
    }
    else
    {
        lblVat.Text = Session["VAT"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["ContactNumber"]))
    {
        lblContactNumber.Text = "N/A";
    }
    else
    {
        lblContactNumber.Text = Session["ContactNumber"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["Fax"]))
    {
        lblFax.Text = "N/A";
    }
    else
    {
        lblFax.Text = Session["Fax"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["District"]))
    {
        lblDistrict.Text = "N/A";
    }
    else
    {
        lblDistrict.Text = Session["District"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["Street"]))
    {
        lblStreet.Text = "N/A";
    }
    else
    {
    lblStreet.Text = Session["Street"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["City"]))
    {
        lblCity.Text = "N/A";
    }
    else
    {
        lblCity.Text = Session["City"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["Code"]))
    {
        lblCode.Text = "N/A";
    }
    else
    {
    lblCode.Text = Session["Code"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["Trading"]))
    {
        lblTrading.Text = "N/A";
    }
    else
    {
    lblTrading.Text = Session["Trading"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["ID"]))
    {
        lblID.Text = "N/A";
    }
    else
    {
    lblID.Text = Session["ID"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["ContactPerson"]))
    {
        lblContactPerson.Text = "N/A";
    }
    else
    {
    lblContactPerson.Text = Session["ContactPerson"].ToString();
    }
    if (string.IsNullOrEmpty((string)Session["Email"]))
    {
        lblMail.Text = "N/A";
    }
    else
    {
    lblMail.Text = Session["Email"].ToString();
    }
}
4

2 回答 2

2

好吧,您那里没有太多选择,如果发生这种情况,您的会话就有问题。也许每个其他请求都在启动一个新会话,请检查以确保它没有发生。

检查:

Session.SessionID;
于 2013-04-10T21:16:31.733 回答
0

我看到一段代码使用TextBox控件,而较低的代码使用Label控件。

你不是,也许,读错了,是吗?

这仅供参考:如果我们填写“N/A”之类的值,我们会在我们的网站上收到客户投诉。大多数人似乎更喜欢看到空格,这也将简化您的代码:

lblVariable.Text = string.Format("{0}", Session["Variable"]);

显然,变量需要随您的 Session 和 Control 变量名称而改变。

于 2013-04-10T21:22:36.937 回答