1

我运行代码,它不会存储它在从屏幕加载时立即停止的值。它应该做的是一个多页应用程序表单,它将从下一个表单将值重新输入到后退按钮上的 texbox 中。

ASP.net 代码太长,无法发布,但基本上它只是 texbox 和 dropbox。如果需要,我可以发布它,但 90% 的主要问题是 C# 代码。

更新:当我说停止时,它会继续代码但不会运行字典方法...我在该方法仅在字典中停止的地方放了一个箭头

C#:

public partial class employment_driversapplication_personalinfo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    Dictionary<string, string> DriversApplicationData = (Dictionary<string, string>) Session["DriversApp"];

    try
    { 



            if (Page.IsPostBack)
            {
                LoadMemoryFromScreen(DriversApplicationData);
            }
            else
            {
                LoadScreenFromMemory(DriversApplicationData);
            }
              }

    catch //(Exception ex)
    {
       // throw new Exception("Exception occured in employment_driversapplication_personalinfo.aspx - Page_Load" + ex.Message);
    }
    finally
    {


    }
} 

private void LoadMemoryFromScreen(Dictionary<string, string> DicDriversApp)
    {

    DicDriversApp["position"] = position.Text; <---Stops here (won't even store this)
    DicDriversApp["fname"] = fname.Text;
    DicDriversApp["middleinitial"] = middleinitial.Text;
    DicDriversApp["lname"] = lname.Text;
    DicDriversApp["birthday"] = birthday.Text;
    DicDriversApp["proofofage"] = proofofage.SelectedValue;
    DicDriversApp["address"] = address.Text;
    DicDriversApp["city"] = city.Text;
    DicDriversApp["state"] = state.Text;
    DicDriversApp["email"] = email.Text;
    DicDriversApp["phone"] = phone.Text;
    DicDriversApp["altphone"] = altphone.Text;
    DicDriversApp["citizen"] = citizen.SelectedValue;
    DicDriversApp["whoreferred"] = whoreferred.Text;
    DicDriversApp["famfriend"] = famfriend.Text;
    DicDriversApp["relationship"] = relationship.Text;
    DicDriversApp["rateofpayexpected"] = rateofpayexpected.Text;
    DicDriversApp["rateofpaytype"] = RadioButtonList1.SelectedValue;
    DicDriversApp["employedNow"] = employednow.SelectedValue;
    DicDriversApp["curremployment"] = curremployment.Text;
    DicDriversApp["pastAddress"] = pastaddress.SelectedValue;
    DicDriversApp["previousAddress"] = previousaddress.Text;
    DicDriversApp["previousCity"] = previouscity.Text;
    DicDriversApp["previousZip"] = previouszip.Text;
    DicDriversApp["previousState"] = previousstate.Text;
    DicDriversApp["previousDuration"] = previousduration.Text;
    DicDriversApp["previousAddress1"] = previousaddress1.Text;
    DicDriversApp["previousCity1"] = previouscity1.Text;
    DicDriversApp["previousZip1"] = previouszip1.Text;
    DicDriversApp["previousState1"] = previousstate1.Text;
    DicDriversApp["previousDuration1"] = previousduration1.Text;

    Session["DriversApp"] = DicDriversApp;
    }

private void LoadScreenFromMemory(Dictionary<string, string> DicDriversApp)
{
    position.Text = DicDriversApp["position"];
    fname.Text = DicDriversApp["fname"] ;
    middleinitial.Text = DicDriversApp["middleinitial"];
    lname.Text = DicDriversApp["lname"];
    birthday.Text = DicDriversApp["birthday"];
    proofofage.SelectedValue = DicDriversApp["proofofage"];
    address.Text = DicDriversApp["address"];
    city.Text = DicDriversApp["city"];
    state.Text = DicDriversApp["state"];
    email.Text = DicDriversApp["email"];
    phone.Text = DicDriversApp["phone"];
    altphone.Text = DicDriversApp["altphone"];
    citizen.SelectedValue = DicDriversApp["citizen"];
    whoreferred.Text = DicDriversApp["whoreferred"];
    famfriend.Text = DicDriversApp["famfriend"];
    relationship.Text = DicDriversApp["relationship"];
    rateofpayexpected.Text = DicDriversApp["rateofpayexpected"];
    RadioButtonList1.SelectedValue = DicDriversApp["rateofpaytype"];
    employednow.SelectedValue = DicDriversApp["employedNow"];
    curremployment.Text = DicDriversApp["curremployment"];
    pastaddress.SelectedValue = DicDriversApp["pastAddress"];
    previousaddress.Text = DicDriversApp["previousAddress"];
    previouscity.Text = DicDriversApp["previousCity"];
    previouszip.Text = DicDriversApp["previousZip"];
    previousstate.Text = DicDriversApp["previousState"];
    previousduration.Text = DicDriversApp["previousDuration"];
    previousaddress1.Text = DicDriversApp["previousAddress1"];
    previouscity1.Text = DicDriversApp["previousCity1"];
    previouszip1.Text = DicDriversApp["previousZip1"];
    previousstate1.Text = DicDriversApp["previousState1"];
    previousduration1.Text = DicDriversApp["previousDuration1"];

}
4

1 回答 1

1

尝试这样的事情:

 private void LoadMemoryFromScreen()
    {    
     Dictionary<string, string> driver = new Dictionary<string, string>();
     driver.Add("position", position.Text);
     driver.Add("othervalue",value.Text); ///etc..
     Session["dict"] = driver;
    }

然后,稍后如果您想访问字典中的值,请使用以下内容:

var dict = (Dictionary<string, string>)Session["dict"];

问题在于您将不得不使用dict.GetElementAt(index)它来检索值,我认为这不是一个很好的方法。

这会起作用,但我有点不明白你为什么要使用字典来做到这一点。我假设您只在页面上加载 1 个人的数据?然后你也可以只创建一个包含所有属性的类,然后你可以传递它而不是使用这个字典/会话黑客。

public class DriversApplicationData
{
public string position {get;set;}
public string firstname {get;set;}
//etc
}

然后,你可以做类似的事情

DriversApplicationData data = new DriversApplicationData();
data.position = position.Text;
data.firstname = fname.Text;

这将更容易维护和检索/插入值。

于 2012-10-02T14:28:33.723 回答