提示"未将对象引用设置到对象的实例。“
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string post1 = Request.Form["title"].ToString();
string post2 = Request.Form["context"].ToString();
TextBox1.Text = post1;
TextBox2.Text = post2;
}
}
这程序我输进去有时可以运行有时不行,不行时提示未将对象引用设置到对象的实例。
也不需要空间引用,也不需要什么new ,为什么书上都这么写,但实际不能运行?
[解决办法]
string post1="";
if(Request.Form["year"]!=null)
{
post1= Request.Form["year"].ToString();
}
string post2="";
if(Request.Form["month"]!=null)
{
post2 =Request.Form["month"].ToString();
}
string post3="";
if(Request.Form["day"]!=null)
{
post3 =Request.Form["day"].ToString();
}
string post4="";
if (Request.Form["hour"] != null)
{
post4 = Request.Form["hour"].ToString();
}
string hebing;
hebing = post1 + post2 + post3 + post4;
TextBox4.Text = hebing;