Systemnullreferenceexception in ASP.NET и код до диез
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Text; using System.Messaging; using System.Net; using System.Net.Mail; namespace exam { public partial class GetFillFromStudent : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Page c = (Page)Context.Handler; Label8.Text = ((Label)c.FindControl("Label1")).Text; Label3.Text = ((Label)c.FindControl("Label1")).Text; Label2.Text = "monaxshroog@gmail.com"; Label4.Text = ((TextBox)c.FindControl("DatabaseG")).Text; Label5.Text = ((TextBox)c.FindControl("NetworkG")).Text; Label6.Text = ((TextBox)c.FindControl("AnalysisG")).Text; Label7.Text = ((TextBox)c.FindControl("hour")).Text; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["seniorConnectionString"].ConnectionString); con.Open(); SqlCommand com = new SqlCommand("select*from dbo.Student", con); if (!String.IsNullOrEmpty(Request.QueryString["pID"])) { int thePID = Convert.ToInt32(Request.QueryString["pID"]); } SqlDataReader dr; dr = com.ExecuteReader(); if (dr.HasRows == true) { dr.Close(); } con.Close(); List labels = new List(); for (int i = 0; i <= 6; i++) { Label label = new Label(); labels.Add(label); } con.Open(); com.ExecuteNonQuery(); SqlDataAdapter sda = new SqlDataAdapter(com); DataTable dt = new DataTable(); sda.Fill(dt); com.ExecuteNonQuery(); con.Close(); } protected void Button1_Click(object sender, EventArgs e) { using (MailMessage mailMessage = new MailMessage(ConfigurationManager.AppSettings["SMTPuser"], Label2.Text)) { mailMessage.Subject = "student"; mailMessage.Body = "Hello amal you can log in the system This your ID:18819 username :amal"; using (SmtpClient smtp = new SmtpClient()) { smtp.EnableSsl = true; smtp.Host = ConfigurationManager.AppSettings["Host"]; smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnabelSSL"]); NetworkCredential networkCred = new NetworkCredential(ConfigurationManager.AppSettings["SMTPuser"], ConfigurationManager.AppSettings["SMTPpassword"]); smtp.UseDefaultCredentials = true; smtp.Credentials = networkCred; smtp.Port = int.Parse(ConfigurationManager.AppSettings["Port"]); smtp.Send(mailMessage); ClientScript.RegisterStartupScript(GetType(), "alter", "alter(Email sent);", true); } } } protected void Button2_Click(object sender, EventArgs e) { using (MailMessage mailMessage = new MailMessage(ConfigurationManager.AppSettings["SMTPuser"], Label2.Text)) { mailMessage.Subject = "student"; mailMessage.Body = "Hello amal you can log in the system This your ID:18819 username :amal"; using (SmtpClient smtp = new SmtpClient()) { smtp.EnableSsl = true; smtp.Host = ConfigurationManager.AppSettings["Host"]; smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnabelSSL"]); NetworkCredential networkCred = new NetworkCredential(ConfigurationManager.AppSettings["SMTPuser"], ConfigurationManager.AppSettings["SMTPpassword"]); smtp.UseDefaultCredentials = true; smtp.Credentials = networkCred; smtp.Port = int.Parse(ConfigurationManager.AppSettings["Port"]); smtp.Send(mailMessage); ClientScript.RegisterStartupScript(GetType(), "alter", "alter(Email sent);", true); } } } } }
Что я уже пробовал:
у меня есть эта проблема на label8 но метка внутри контроллера она имеет значение