我有mail.aspx 页面。哪些必须有一个撰写邮件设施?此外,用户可以从用户帐户到用户、cc 和 bccs 中进行选择。当更新面板更新方法从文本框中调用所有先前的值变空时,与它们一起。为了避免它们,我创建了一种方法,该方法采用以前的值并针对特定条件使用它们进行渲染。
这是我的方法:
private void SetViewStateData(bool sTitle, bool sFromuser, bool sTouser, bool sCc, bool sBcc, bool sBody)
{
if (sTitle.Equals(true))
{
ViewState["sTitle"] = Request.Form.Get("txt_ComName1");
}
else
{
ViewState["sTitle"] = string.Empty;
}
if (sFromuser.Equals(true))
{
ViewState["sFromuser"] = Request.Form.Get("txt_ComName2");
}
else
{
ViewState["sFromuser"] = string.Empty;
}
if (sTouser.Equals(true))
{
ViewState["sTouser"] = Request.Form.Get("txt_ComName3");
}
else
{
ViewState["sTouser"] = string.Empty;
}
if (sCc.Equals(true))
{
ViewState["sCc"] = Request.Form.Get("txt_ComName4");
}
else
{
ViewState["sCc"] = string.Empty;
}
if (sBcc.Equals(true))
{
ViewState["sBcc"] = Request.Form.Get("txt_ComName5");
}
else
{
ViewState["sBcc"] = string.Empty;
}
if (sBody.Equals(true))
{
ViewState["sBody"] = Request.Form.Get("CKEditor1");
}
else
{
ViewState["sBody"] = string.Empty;
}
txt_ComName1.Text = sTitle.Equals(false) ? string.Empty : ViewState["sTitle"].ToString();
txt_ComName2.Text = sFromuser.Equals(false) ? string.Empty : ViewState["sFromuser"].ToString();
txt_ComName3.Text = sTouser.Equals(false) ? string.Empty : ViewState["sTouser"].ToString();
txt_ComName4.Text = sCc.Equals(false) ? string.Empty : ViewState["sCc"].ToString();
txt_ComName5.Text = sBcc.Equals(false) ? string.Empty : ViewState["sBcc"].ToString();
CKEditor1.Text = sBody.Equals(false) ? string.Empty : ViewState["sBody"].ToString();
}
如果布尔状态为 true 或 string.empty,则当 txt_ComName2.Text 从视图状态值设置时会引发错误。但是,这适用于第一个文本框。第二次它给了我一个错误,例如:
Server Error in '/EASYMAIL_METRO' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 240: }
Line 241: txt_ComName1.Text = sTitle.Equals(false) ? string.Empty : ViewState["sTitle"].ToString();
Line 242: txt_ComName2.Text = sFromuser.Equals(false) ? string.Empty : ViewState["sFromuser"].ToString();
Line 243: txt_ComName3.Text = sTouser.Equals(false) ? string.Empty : ViewState["sTouser"].ToString();
Line 244: txt_ComName4.Text = sCc.Equals(false) ? string.Empty : ViewState["sCc"].ToString(); Source File: c:\shalin\EASYMAIL_METRO\mail.aspx.cs Line: 242
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
mail.SetViewStateData(Boolean sTitle, Boolean sFromuser, Boolean sTouser, Boolean sCc, Boolean sBcc, Boolean sBody) in c:\shalin\EASYMAIL_METRO\mail.aspx.cs:242
mail.btn_add_Click(Object sender, EventArgs e) in c:\shalin\EASYMAIL_METRO\mail.aspx.cs:1823
mail.Page_Load(Object sender, EventArgs e) in c:\shalin\EASYMAIL_METRO\mail.aspx.cs:71
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +95
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678
这是怎么回事...请帮助我,伙计们...