在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>");
}
}
}

}



...全文
223 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
宝_爸 2014-11-06
  • 打赏
  • 举报
回复
印象中InitializeComponent只有winform才有。 新建个web application和一个web site,没有InitializeComponent啊。也不需要自己关联event啊。
宝_爸 2014-11-06
  • 打赏
  • 举报
回复
这东西不是都是vs自己生成的吗。你手动修改了?
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace HistoryMenu { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.Filter = "*.*(所有文件)|*.*";//设置打开文件格式 if (openFileDialog1.ShowDialog() == DialogResult.OK)//判断是否打开选择文件对话框 { StreamWriter s = new StreamWriter("Menu.ini", true);//实例化写入流对象 s.WriteLine(openFileDialog1.FileName);//向INI文件写入内容 s.Flush();//清除缓冲区 s.Close();//关闭写入流 System.Diagnostics.Process.Start(openFileDialog1.FileName);//打开选择的文件 } Form1_Load(sender, e);//重新加载菜单 } private void Form1_Load(object sender, EventArgs e) { 文件ToolStripMenuItem.DropDownItems.Clear();//清空菜单 ToolStripMenuItem menuitem1 = new ToolStripMenuItem("打开");//实例化打开菜单 文件ToolStripMenuItem.DropDownItems.Insert(0, menuitem1);//添加打开菜单 menuitem1.Click += new EventHandler(打开ToolStripMenuItem_Click);//为打开菜单指定单击事件 ToolStripMenuItem menuitem2 = new ToolStripMenuItem("退出");//实例化退出菜单 文件ToolStripMenuItem.DropDownItems.Insert(1, menuitem2);//添加退出菜单 StreamReader sr = new StreamReader("Menu.ini");//实例化读取流对象 int i = this.文件ToolStripMenuItem.DropDownItems.Count - 1;//定义历史记录位置 while (sr.Peek() >= 0)//从INI文件读取历史记录 { ToolStripMenuItem menuitem = new ToolStripMenuItem(sr.ReadLine());//实例化历史菜单 this.文件ToolStripMenuItem.DropDownItems.Insert(i, menuitem);//添加历史菜单 i++;//重新指定历史记录位置 menuitem.Click += new EventHandler(menuitem_Click);//为历史菜单指定单击事件 } sr.Close();//关闭读取流 } private void menuitem_Click(object sender, EventArgs e) { try { ToolStripMenuItem menu = (ToolStripMenuItem)sender;//获取菜单单击项 System.Diagnostics.Process.Start(menu.Text);//根据历史菜单打开指定文件 } catch { } } } }

111,112

社区成员

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

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

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