无法获得值的有关问题,朋友。
<input type="file">无法获得值的问题,请教各位朋友。急
一、环境:VS2003,WEB.NET,C#
二、前台HTML文件:
三、后面CS文件:
四、我的问题是,这个HTML控件为何取不到值<INPUT TYPE="file" RUNAT="server" STYLE="WIDTH:320px" NAME="up_file" id="up_file">,他取不到值,后面的代码一句都不会执行,取不到值,到了这句fileLength = upFile.ContentLength;就提示“未将对象引用到实例”,请朋友们帮帮我。感谢
------解决方案--------------------


我这里是测试出有值的
------解决方案--------------------
可怜的娃,居然还用VS2003。。。
一、环境:VS2003,WEB.NET,C#
二、前台HTML文件:
<%@ Page language="c#" Codebehind="shangchuan.aspx.cs" AutoEventWireup="false" Inherits="EKP.OTC_J.shangchuan" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>shangchuan</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<BODY bgcolor="#ffffff">
<FORM ENCTYPE="multipart/form-data" RUNAT="server" ID="Form1">
<TABLE RUNAT="server" WIDTH="700" ALIGN="left" ID="Table1" cellpadding="0" cellspacing="0"
border="0">
<TR>
<TD>上传图片(选择你要上传的图片)</TD>
<TD>
<INPUT TYPE="file" RUNAT="server" STYLE="WIDTH:320px" NAME="up_file" id="up_file">
</TD>
</TR>
<TR>
<TD>
<asp:Label RUNAT="server" ID="txtMessage" FORECOLOR="red" MAINTAINSTATE="false" />
</TD>
<TD>
<asp:Button RUNAT="server" WIDTH="239" TEXT="Upload Image" ID="Button1" />
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
三、后面CS文件:
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.Configuration;
using System.Data.Odbc;
using System.IO;
namespace EKP.OTC_J
{
public class shangchuan : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtDescription;
protected System.Web.UI.WebControls.Label txtMessage;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.HtmlControls.HtmlInputFile up_file;
protected System.Web.UI.HtmlControls.HtmlTable Table1;
protected Int32 fileLength = 0;
private void Page_Load(object sender, System.EventArgs e)
{
}
#region
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
HttpPostedFile upFile = up_file.PostedFile;//HttpPostedFile对象,用来读取上传图片的属性
fileLength = upFile.ContentLength;//记录文件的长度
try
{
if(fileLength==0)
{
txtMessage.Text = "请选择要上传的文件!";
}
else
{
byte[] fileByte = new byte[fileLength];
Stream fileStream = upFile.InputStream;
fileStream.Read(fileByte,0,fileLength);
string strConnHR=ConfigurationSettings.AppSettings["OTCConnect"];
OdbcConnection myConnHR=new OdbcConnection(strConnHR);
myConnHR.Open();
string inpic="insert into TM_PSC_JL (BGWJ)value(@photo) where CPNM='225'and PH='336'";
OdbcCommand comm = new OdbcCommand(inpic,myConnHR);
comm.Parameters.Add(new OdbcParameter("@photo",SqlDbType.Image));
comm.Parameters["@photo"].Value = fileByte;
comm.ExecuteNonQuery();
txtMessage.Text = "你已经成功的上传了图片";
}
}
catch(Exception ex)
{
txtMessage.Text = ex.Message.ToString();
}
}
}
}
四、我的问题是,这个HTML控件为何取不到值<INPUT TYPE="file" RUNAT="server" STYLE="WIDTH:320px" NAME="up_file" id="up_file">,他取不到值,后面的代码一句都不会执行,取不到值,到了这句fileLength = upFile.ContentLength;就提示“未将对象引用到实例”,请朋友们帮帮我。感谢
------解决方案--------------------
我这里是测试出有值的
------解决方案--------------------