看看你有没有哪个对象 在使用前是null
或者你用到了哪个控件 却没有在aspx或者aspx.cs中定义
最好贴出你的代码,和错误信息在哪行

解决方案 »

  1.   

    //uploadFile.aspx.csusing System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;namespace test
    {
    /// <summary>
    /// uploadFile 的摘要说明。
    /// </summary>
       

    public class uploadFile : UserControl
    {
    private System.Web.UI.WebControls.TextBox FileName; public string FileName_Text
    {
    get
    {
    return FileName.Text;
    }
    set
    {
    FileName.Text = value;
    }
    } protected void ButtonClick(object sender,EventArgs e)
    {
    FileName.Text = FileName_Text + "aoa";
    }

    }
    }//-----------------------------------------------
    //uploadFile.ascx<%@ Control Language="C#" Inherits="test.uploadFile"%><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <link rel="stylesheet" href="CSS/ALL.CSS">
    <style type="text/css">
    <!--
    .style1 {color: #0033FF}
    .style2 {color: #FFFFFF}
    -->
    </style>
    </head>
        <p>&nbsp;</p>
        <div align="center">
          <table width="60%" border="1">
            <caption>&nbsp;
            </caption>
            <tr bgcolor="#457aac">
              <td colspan="2"><div align="center" class="style2">【 文 件 上 传 】</div></td>
            </tr>
            <tr>
              <td width="37%" bgcolor="#FFFFFF"><div align="center" class="style3 style1">请输入该文件要显示的文件名</div></td>
              <td width="63%"><div align="left">
                <asp:TextBox id="FileName" runat="server"/>
              </div></td>
            </tr>
            <tr>
              <td bgcolor="#FFFFFF"><div align="center" class="style3 style1">请选择要上传文件</div></td>
              <td><div align="left">
                <input name="file" type="file" id="file">
              </div></td>
            </tr>
            <tr>
              <td colspan="2"><div align="center">
                <asp:Button ID="submit" OnClick="ButtonClick" runat="server" Text="submit"></asp:Button>
              </div></td>
            </tr>
          </table>
        </div>
    //-------------------------------------------------------------------------------
    //upload.aspx<%@ Register TagPrefix="uploadFile" TagName="uploadFile" src="uploadFile.ascx" Assembly="test"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <body>
    <script language="c#">
      protected void Page_Load(object sender,EventArgs e)
    {
    if(IsPostBack)
    {
    form1.style.visibility = "hidden";
    }
    }
    </script>
     <div id="panel" style="visibility:visible">
      <form name="form1" method="post" action="ShowData.aspx" enctype="multipart/form-data" runat="server">
       <uploadFile:uploadFile id="upload" runat="server"/>
      </form>
     </div>
    </body>
    </html>
      

  2.   

    //uploadFile.aspx.cs 应该是//uploadFile.ascx.cs 吧,把这个文件删掉,把uploadFile.ascx从项目中排除然后包括在项目中,看看前后 uploadFile.ascx.cs有什么区别就知道是怎么了
      

  3.   

    1. don't use private, use protected or public:private System.Web.UI.WebControls.TextBox FileName
    ===>
    protected System.Web.UI.WebControls.TextBox FileName2. give form a id:  <form ID="form1" method="post" action="ShowData.aspx" enctype="multipart/form-data" runat="server">3. add a runat="server" to your script block:<script language="c#" runat="server">
      protected void Page_Load(object sender,EventArgs e)
    {
    if(IsPostBack)
    {
    form1.Style["visibility"] = "hidden";
    }
    }
    </script>4. <%@ Register TagPrefix="uploadFile" TagName="uploadFile" src="uploadFile.ascx" Assembly="test"%>
    ===>
    <%@ Register TagPrefix="uploadFile" TagName="uploadFile" src="uploadFile.ascx"%>