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

}



...全文
212 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
宝_爸 2014-11-06
  • 打赏
  • 举报
回复
印象中InitializeComponent只有winform才有。 新建个web application和一个web site,没有InitializeComponent啊。也不需要自己关联event啊。
宝_爸 2014-11-06
  • 打赏
  • 举报
回复
这东西不是都是vs自己生成的吗。你手动修改了?
Example002-渐显的窗体 Example003-使程序始终在前面 Example004-将窗体编译成类库 Example005-继承窗体的设计 Example006-设计多边形窗体 Example007-用获取路径的方法得到圆形窗体 Example008-分割窗体 Example009-在菜单中加入图标 Example010-渐变的窗口背景 Example011-使用任务栏的状态区 Example012-在运行时更新状态栏信息 Example013-无标题窗体的拖动 Example014-设置应用程序的图标 Example015-共享菜单项 Example016-动态设置窗体的光标 Example017-自己绘制菜单 Example018-向窗体的系统菜单添加菜单项 namespace Example018_向窗体的系统菜单添加菜单项 { /// /// Form1 的摘要说明。 /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; /// /// 必需的设计器变量。 /// private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2}); this.menuItem1.Text = "File"; // // menuItem2 // this.menuItem2.Index = 0; this.menuItem2.Text = "Exit"; this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 273); this.Menu = this.mainMenu1; this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); } #endregion /// /// 应用程序的主入口点。 /// [STAThread] [System.Runtime.InteropServices.DllImport("user32")] private static extern IntPtr GetSystemMenu(IntPtr hwnd,bool bRevert); [System.Runtime.InteropServices.DllImport("user32")] private static extern IntPtr AppendMenu(IntPtr hMenu,int wFlags,IntPtr wIDNewItem,string lpNewItem); const int MF_POPUP = 0x0010; const int MF_SEPARATOR = 0x0800; static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { IntPtr mnuSystem; mnuSystem=GetSystemMenu(this.Handle,false); AppendMenu(mnuSystem, MF_SEPARATOR, (IntPtr)0, ""); for(int i= 0;i /// Form1 的摘要说明。 /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; /// /// 必需的设计器变量。 /// private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // Thread.CurrentThread.CurrentUICulture=new CultureInfo("zh-cn"); InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.AccessibleDescription = ((string)(resources.GetObject("button1.AccessibleDescription"))); this.button1.AccessibleName = ((string)(resources.GetObject("button1.AccessibleName"))); this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("button1.Anchor"))); this.button1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button1.BackgroundImage"))); this.button1.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("button1.Dock"))); this.button1.Enabled = ((bool)(resources.GetObject("button1.Enabled"))); this.button1.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("button1.FlatStyle"))); this.button1.Font = ((System.Drawing.Font)(resources.GetObject("button1.Font"))); this.button1.Image = ((System.Drawing.Image)(resources.GetObject("button1.Image"))); this.button1.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("button1.ImageAlign"))); this.button1.ImageIndex = ((int)(resources.GetObject("button1.ImageIndex"))); this.button1.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("button1.ImeMode"))); this.button1.Location = ((System.Drawing.Point)(resources.GetObject("button1.Location"))); this.button1.Name = "button1"; this.button1.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("button1.RightToLeft"))); this.button1.Size = ((System.Drawing.Size)(resources.GetObject("button1.Size"))); this.button1.TabIndex = ((int)(resources.GetObject("button1.TabIndex"))); this.button1.Text = resources.GetString("button1.Text"); this.button1.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("button1.TextAlign"))); this.button1.Visible = ((bool)(resources.GetObject("button1.Visible"))); // // Form1 // this.AccessibleDescription = ((string)(resources.GetObject("$this.AccessibleDescription"))); this.AccessibleName = ((string)(resources.GetObject("$this.AccessibleName"))); this.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("$this.Anchor"))); this.AutoScaleBaseSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScaleBaseSize"))); this.AutoScroll = ((bool)(resources.GetObject("$this.AutoScroll"))); this.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMargin"))); this.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMinSize"))); this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this.ClientSize"))); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button1}); this.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("$this.Dock"))); this.Enabled = ((bool)(resources.GetObject("$this.Enabled"))); this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("$this.ImeMode"))); this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location"))); this.MaximumSize = ((System.Drawing.Size)(resources.GetObject("$this.MaximumSize"))); this.MinimumSize = ((System.Drawing.Size)(resources.GetObject("$this.MinimumSize"))); this.Name = "Form1"; this.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("$this.RightToLeft"))); this.StartPosition = ((System.Windows.Forms.FormStartPosition)(resources.GetObject("$this.StartPosition"))); this.Text = resources.GetString("$this.Text"); this.Visible = ((bool)(resources.GetObject("$this.Visible"))); this.ResumeLayout(false); } #endregion /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.Run(new Form1()); } } }
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,097

社区成员

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

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

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