私はmail.aspxページを持っています。メール機能を作成する必要があるのはどれですか? また、ユーザーはユーザー アカウントからユーザー、cc、bccs を選択できます。更新パネルの更新メソッドが、テキスト ボックスから以前のすべての値を呼び出して空になると、それらと一緒に表示されます。それらを回避するために、以前の値を取得して特定の条件でレンダリングする 1 つのメソッドを作成します。
ここに私の方法があります:
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();
}
bool statusがtrueまたはstring.emptyの場合、txt_ComName2.Textがビューステート値から設定されると、これによりエラーが発生します。ただし、これは最初のテキスト ボックスでは問題なく機能します。2番目に次のようなエラーが表示されます:
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
これの何が悪いんだ...助けてくれ、みんな...