在InitializeComponent() 的System.EventHandler 报未将对象引用设置到对象的实例 错误

coreyyan88 2014-11-05 10:43:00
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="js/selcity.js"></script>
<script type="text/javascript" src="js/selSpecialty.js"></script>
<script type="text/javascript" src="js/Certificatetype.js"></script>
</head>
<body onload="initProvince();initSpecialty();inittype()">
<form id="form1" method="post" action="">
<div>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="12%"><span class="star"> * </span>真实姓名</th>
<td width="88%"><input type="text" class="textbox" name="RealName" id="RealName" value="" size="20" maxlength="10" />
  
<span class="">性别</span>
<select name="Sex" id="Sex" class="select">
<option value="男">男</option>
<option value="女">女</option>
</select>
</tr>
<tr>
<th><span class="star"> * </span>出生年月</th>
<td>
<input type="text" maxlength="4" size="6" id="birthdayyear" name="birthdayyear" value="">年(YYYY)
  
工作年限
<input type="text" maxlength="2" size="2" id="birthdaymonth" name="birthdaymonth" value="">月(MM)
</td>
</tr>

<tr id="postSubtn">
<td height="40"> </td>
<td valign="bottom"><input type="submit" id="btnpulish_ServerClick" name="btnpulish_ServerClick" value="立即发布"></td>
</tr>
</table>
</div>
</form>
</body>
</html>




using System;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Web.SessionState;
using System.Data.SqlClient;
using OleDbHelper;



public partial class _Default : System.Web.UI.Page
{
public System.Web.UI.HtmlControls.HtmlInputText RealName;
public System.Web.UI.HtmlControls.HtmlSelect Sex;
public System.Web.UI.HtmlControls.HtmlInputText birthdayyear;
public System.Web.UI.HtmlControls.HtmlInputText birthdaymonth;

public System.Web.UI.HtmlControls.HtmlInputButton btnpulish;
public System.Web.UI.WebControls.DataGrid DG_Persons;
OleDbConnection MyConn;

protected void Page_Load(object sender, EventArgs e)
{
BindGrid();
}
private void BindGrid()
{

MyConn = DB.CreateDB();
MyConn.Open();
OleDbCommand cmd = new OleDbCommand("select * from PersonCertifiate", MyConn);
OleDbDataReader dr = cmd.ExecuteReader();
MyConn.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//

base.OnInit(e);
InitializeComponent();
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{

this.btnpulish.ServerClick += new System.EventHandler(this.btnpulish_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);



}
#endregion


private void btnpulish_ServerClick(object sender, System.EventArgs e)
{
{
try
{
MyConn = DB.CreateDB();

string strRealName = RealName.ToString();
string strSex = Sex.Value;
string strbirthdayyear = birthdayyear.ToString();
string strbirthdaymonth = birthdaymonth.ToString();


if (strRealName == null || strSex == null || strbirthdayyear == null || strbirthdaymonth == null )
{

Response.Write("<script>alert('数据添加失败')</script>");

}
else
{
MyConn.Open();
OleDbCommand cmd1 = new OleDbCommand("insert into PersonCertifiate(Realname,sex,birthdayyear,birthdaymonth) values('" + strRealName + "','" + strSex + "','" + strbirthdayyear + "','" + strbirthdaymonth + "')", MyConn);
cmd1.ExecuteNonQuery();
Response.Write("<script>alert('数据添加成功')/script>");
MyConn.Close();
}


}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "')</script>");
}
}
}

}



...全文
202 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
宝_爸 2014-11-06
  • 打赏
  • 举报
回复
印象中InitializeComponent只有winform才有。 新建个web application和一个web site,没有InitializeComponent啊。也不需要自己关联event啊。
宝_爸 2014-11-06
  • 打赏
  • 举报
回复
这东西不是都是vs自己生成的吗。你手动修改了?

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧