2016-05-16 6 views
-1

(初心者の方でも、言語はほとんど分かりません) ボタンの機能は特定のメールにメッセージを送信することです。私はメッセージングのためにウェブサービスを使用しましたが、このエラーはポップアップ表示され続けます。 ここにボタンのコードは次のとおりです。System.NullReferenceException:オブジェクト参照がオブジェクトのインスタンスに設定されていません。

protected void Button1_Click(object sender, EventArgs e) 
    { 
     Msg.Service M = new Msg.Service(); 
     M.InsertNewMessage(Session["Email"].ToString(), "[email protected]", this.TextBox2.Text.ToString()); 
     this.Label4.Text = "the massege had sent succesfully"; 
     this.Label4.Visible = true; 
    } 

これはエラーページで強調表示された行です。

M.InsertNewMessage(Session["Email"].ToString(), "[email protected]", this.TextBox2.Text.ToString()); 

、ここInsertNewMessage関数のコードは次のとおりです。

[WebMethod] 
    public string InsertNewMessage(string sender, string To, string message) 
    { 
     DateTime d = DateTime.Now; 
     message m = new message(sender, To, message, d); 
     m.SaveToDB(); 
     return "Inserted successfully"; 
    } 
+0

おそらく 'Session [" Email "]'はnullです。 – CoolBots

答えて

0

Propession Session ["Email"]は空です。あなたはどこかにそれを設定してください。

関連する問題

 関連する問題