-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";
}
おそらく 'Session [" Email "]'はnullです。 – CoolBots