接上页:
private void Submit_Click(object sender, System.EventArgs e)
{   //获得来源 if(Page.IsValid)
{
  addArticle(); 
string userclass=(string)Session["userclass"];
int i=(int)Session["addnchk"];
if(userclass.Trim()=="系统管理员"||i==1)
{
addhints();
addClassNum();
}
} } private void upload_Click(object sender, System.EventArgs e)
{

if(FileUp.PostedFile.ContentLength!=0)
{

if(FileUp.PostedFile.ContentType=="image/pjpeg" || FileUp.PostedFile.ContentType=="image/gif"||FileUp.PostedFile.ContentType=="image/bmp")    //设置上传文件类型
{  
string filename=FileUp.PostedFile.FileName;  //取得文件名
int i=filename.Length;
filename=filename.Remove(0,i-4);
string s=DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+DateTime.Now.Millisecond.ToString();
string  d=Server.MapPath("../upfiles/")+s+filename ;    //设置文件名

      
FileUp.PostedFile.SaveAs(d);  //保存文件
Body.Value+="<img src=../upfiles/"+s+filename+">"; //更改新闻内容
Label1.Text="上传成功";

}

else Label1.Text="只能上传图形文件";
}
else Label1.Text="请选择上传文件";


} private void Button1_Click(object sender, System.EventArgs e)
{
Session["Title"]=Title.Value;
Session["Body"]=Body.Value;
Session["Summary"]=Summary.Value;
Session["Key"]=Key.Value;
Session["Author"]=Author.Value;
//Session["Source"]=Source.Value;
  
// Response.Redirect("admin_articlePreView.aspx",false);

}
}
}
admin_articleAdd.aspx:。。
<%@ Page Language="c#" Inherits="WebNews.admin.admin_articleAdd" Src="admin_articleAdd.aspx.cs" AutoEventWireup="false" %>
<%@ Register TagPrefix="dntb" Namespace="DotNetTextBox" Assembly="DotNetTextBox" %><HTML>
<HEAD>
<LINK href="../style.css" type="text/css" rel="stylesheet">
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript" type="text/javascript"> 
<!-- 
var province_ar=new Array("","学历文凭|a,b,文秘3,金融,国际贸易,会计,英语,计算机应用,法律,艺术设计","成人高教|工商企业管理,国际经济与贸易,外贸英语,计算机应用与管理,艺术设计","高教自考|饭店管理,工商企业管理,中英合作商务管理,保险,国际贸易,英语,电子商务,计算机及应用,法律,广告"); function show_province() 

var pro_tmp=document.all.province; 
for (m=pro_tmp.options.length-1;m>0;m--) 
pro_tmp.options[m]=null; for(i=0;i<province_ar.length;i++) 

if(province_ar[i]!="") 

tmp=province_ar[i].split("|"); 
pro_tmp.options[i]=new Option(tmp[0],tmp[0]); 



function show_city(sc) 

var temp=document.all.city; 
for (m=temp.options.length-1;m>0;m--) 
temp.options[m]=null; if(province_ar[sc]!="") 

tmp=province_ar[sc].split("|"); 
tmp=tmp[1]; 
tmp=tmp.split(","); 
for(i=0;i<tmp.length;i++) 

temp.options[i]=new Option(tmp[i],tmp[i]); 



setTimeout("show_province();",20);//第一个搜索中省份城市对应 
--> 
</script>  </HEAD>
<body runat="server">
<div align="center">
<!--#include file="../inc/getubb.js" --><asp:label id="myLabel" runat="server" width="100%"></asp:label></div>
<form id="myForm" name="myForm" runat="server" enctype="multipart/form-data" method="post">
&nbsp;
<table class="border" cellSpacing="0" cellPadding="0" width="800" align="center" border="0">
<tr align="middle" height="25">
<td class="title"><b>添加新闻</b></td>
</tr>
<tr height="120">
<td class="tdbg">
<blockquote><br>
新闻类型:
<select id=province  
     onchange=show_city(this.options.selectedIndex)> 
<OPTION value="" selected>请选择类别</option> 
</select> 
<select id=city> 
   <OPTION value="" selected>请选择专业</OPTION> 
</select> 
<br>
新闻标题: <input id="Title" type="text" maxLength="100" size="80" name="Title" runat="server">
<asp:requiredfieldvalidator id="Requiredfieldvalidator3" runat="server" Display="Dynamic" ErrorMessage="*请输入新闻标题" ControlToValidate="Title" NAME="Requiredfieldvalidator3"></asp:requiredfieldvalidator><br>
<div style="MARGIN: 4px 0px">新闻属性:<asp:checkbox id="Headline" runat="server"></asp:checkbox>头条新闻</LABEL>&nbsp;&nbsp;|
<asp:checkbox id="HighLight" runat="server"></asp:checkbox>标题醒目</LABEL>
</div>
UBB 标签:<!--#include file="../inc/ubb.inc" -->
<br>
<INPUT id="FileUp" type="file" name="File1" runat="server">
<asp:Button id="upload" runat="server" Text="上 传"></asp:Button>
<asp:Label id="Label1" runat="server" ForeColor="Red"></asp:Label><BR>
<TEXTAREA id="Body" rows="17" cols="85" runat="server"> </TEXTAREA>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ControlToValidate="Body" ErrorMessage="*请输入新闻内容"></asp:RequiredFieldValidator>
<br>
新闻简介: <TEXTAREA id="Summary" rows="3" cols="75" runat="server"></TEXTAREA>
<asp:customvalidator id="CustomValidator1" runat="server" Display="Dynamic" ErrorMessage="*简介最多200字" ControlToValidate="Summary"></asp:customvalidator><br>
相关新闻: <input id="Key" type="text" maxLength="100" size="60" runat="server"><br>
<script language="javascript">
function setAuthor(str)
{
var obj=document.myForm.Author;
obj.value=str;
}
</script>
作者: <input id="Author" type="text" maxLength="100" size="60" runat="server"> ← <A href="javascript:setAuthor('未知')">
未知</A>,<A href="javascript:setAuthor('佚名')">佚名</A>
<br>
来源: <INPUT id="Source" type="text" maxLength="100" size="60" runat="server">
<br>
<br>
<br>
<asp:button id="Submit" runat="server" text="添 加"></asp:button>
<asp:Button id="Button1" runat="server" Text="预览设置保存"></asp:Button>
<a href="admin_articlePreView.aspx" target="_blank"><font color="#ff0000" size="4" face="Geneva, Arial, Helvetica, sans-serif">
<strong>预 览</strong></font></a> (请先保存设置后再预览)</blockquote>
</td>
</tr>
</table>
</form>
<!--#include file="../foot.inc" -->
</body>
</HTML>

解决方案 »

  1.   

    堆栈跟踪: 
    [NullReferenceException: 未将对象引用设置到对象的实例。]
       WebNews.admin.admin_articleAdd.addArticle() +32
       WebNews.admin.admin_articleAdd.Submit_Click(Object sender, EventArgs e) +39
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain() +1277 
      

  2.   

    admin_articleAdd.aspx文件不用看了,麻放各位了!using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Configuration;
    namespace WebNews.admin
    {
    /// <summary>
    /// admin_articleAdd 的摘要说明。
    /// </summary>
    public class admin_articleAdd : System.Web.UI.Page
    {........
                   protected System.Web.UI.HtmlControls.HtmlSelect city;
                   protected System.Web.UI.HtmlControls.HtmlSelect province ;
             private void addArticle()    //发表文章
    {
    int hl=0;
    int HL=0;
    string classname=city.Value.Trim(); //获得分类名
                           try
                               {
                                 SqlParameter big=cmd.Parameters.Add("@big",SqlDbType.Char,400);
    big.Value=province.Value.Trim();
                               catch(Exception e)
    {
    Console.WriteLine("Exception in Main: " + e.Message); //出错处理
     
    }
    }             #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.upload.Click += new System.EventHandler(this.upload_Click);
    this.CustomValidator1.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.CustomValidator1_ServerValidate);
    this.Submit.Click += new System.EventHandler(this.Submit_Click);
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
    {
       if(Summary.Value.Length>200)
       {
       args.IsValid=false   ;
       }
                else
       args.IsValid=true;
    } private void Submit_Click(object sender, System.EventArgs e)
    {   //获得来源 if(Page.IsValid)
    {
      addArticle(); 
    string userclass=(string)Session["userclass"];
    int i=(int)Session["addnchk"];
    if(userclass.Trim()=="系统管理员"||i==1)
    {
    addhints();
    addClassNum();
    }
    } }#region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.upload.Click += new System.EventHandler(this.upload_Click);
    this.CustomValidator1.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.CustomValidator1_ServerValidate);
    this.Submit.Click += new System.EventHandler(this.Submit_Click);
    his.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
    {
     if(Summary.Value.Length>200)
      {
      args.IsValid=false   ;
       }
                else
       args.IsValid=true;
    } private void Submit_Click(object sender, System.EventArgs e)
    {   //获得来源 if(Page.IsValid)
    {
      addArticle(); 
    string userclass=(string)Session["userclass"];
    int i=(int)Session["addnchk"];
    if(userclass.Trim()=="系统管理员"||i==1)
    {
    addhints();
    addClassNum();
    }
    } }
      

  3.   

    我怀以是去dropdownlist的时候留下一些应该去掉的东西吧,困为原先是没问题的
      

  4.   

    如果这里是全部的代码的话,我觉得是你差了一个按钮的事件
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    你的代码里并没有Button1.Click事件