imgUpload.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.IO; using System.Data.SqlClient; using System.Configuration; using System.Text; namespace QingdaoCate.Web.Image { public class ImgUpload : Page { protected System.Web.UI.HtmlControls.HtmlInputFile UploadFile; protected System.Web.UI.WebControls.Button btnUpload; protected System.Web.UI.WebControls.Label message; private void Page_Load(object sender, System.EventArgs e) { btnUpload.Attributes["onClick"]="return imguploadValid();"; } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.btnUpload.Click += new System.EventHandler(this.btnUpload_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btnUpload_Click(object sender, System.EventArgs e) { Business.Image image=new Business.Image(); int currentRow=image.Insert(UploadFile.PostedFile); if(currentRow> 0) { StringBuilder strScript = new StringBuilder(); strScript.Append(@"<script language=JavaScript>" + "\n"); strScript.Append(@" window.returnValue='" +currentRow+ "';" + "\n"); strScript.Append(@" window.opener=null;window.top.close(this);" + "\n"); strScript.Append(@"</script>"); Page.RegisterClientScriptBlock("setValue", strScript.ToString()); } else { message.Text="图片上传的过程中出现错误"; } } } }
chinjs.js里面的//弹出窗口,输入图片 function OpenDialog(arg) { var ret = window.showModalDialog("../image/imgupload.aspx","Dialog Arguments Value","dialogHeight: 150px; dialogWidth: 330px; dialogTop: 200px; dialogLeft: 300px; edge: Raised; center: Yes; help: no; resizable:no; status: no;"); if (ret != null) arg.value = ret; }
<body> <base target="_self">
就是在执行close的时候,没有直接关闭,而是出现提示窗口问是否关闭窗口?
{
var ret = window.showModalDialog("../image/imgupload.aspx","","dialogHeight: 150px; dialogWidth: 330px; dialogTop: 200px; dialogLeft: 300px; edge: Raised; center: Yes; help: no; resizable:no; status: no;");
if (ret != null)
arg.value = ret;
}与这个的参数有没有关系?
这句话好像不起作用?
<%@ Page language="c#" Codebehind="ImgUpload.aspx.cs" AutoEventWireup="false" Inherits="QingdaoCate.Web.Image.ImgUpload" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<base target="_self">
<script language="javascript" src="../../JS/ChinJS.js"></script>
<LINK href="../../Style/ChinStyle.css" type="text/css" rel="stylesheet">
</HEAD>
<body>
<form id="form1" name="form1" encType="multipart/form-data" runat="server">
<TABLE id="Table1" cellSpacing="1" cellPadding="3" width="300" border="0" class="tblBody">
<TR>
<TD colSpan="3" class="tblHeader">上传图片</TD>
</TR>
<TR>
<TD noWrap>选择图片</TD>
<TD>
<input id="UploadFile" type="file" runat="server" NAME="UploadFile" class="TextBox"></TD>
<TD>
<asp:button Text="上传" runat="server" ID="btnUpload" CssClass="Button" /></TD>
</TR>
<TR>
<TD colSpan="3" class="tdCenter">
<asp:Label id="message" runat="server" CssClass="message"></asp:Label></TD>
</TR>
</TABLE>
</form>
</body>
</HTML>
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.IO;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
namespace QingdaoCate.Web.Image
{
public class ImgUpload : Page
{
protected System.Web.UI.HtmlControls.HtmlInputFile UploadFile;
protected System.Web.UI.WebControls.Button btnUpload;
protected System.Web.UI.WebControls.Label message;
private void Page_Load(object sender, System.EventArgs e)
{
btnUpload.Attributes["onClick"]="return imguploadValid();";
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnUpload.Click += new System.EventHandler(this.btnUpload_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnUpload_Click(object sender, System.EventArgs e)
{
Business.Image image=new Business.Image();
int currentRow=image.Insert(UploadFile.PostedFile);
if(currentRow> 0)
{
StringBuilder strScript = new StringBuilder();
strScript.Append(@"<script language=JavaScript>" + "\n");
strScript.Append(@" window.returnValue='" +currentRow+ "';" + "\n");
strScript.Append(@" window.opener=null;window.top.close(this);" + "\n");
strScript.Append(@"</script>");
Page.RegisterClientScriptBlock("setValue", strScript.ToString());
}
else
{
message.Text="图片上传的过程中出现错误";
}
}
}
}
function OpenDialog(arg)
{
var ret = window.showModalDialog("../image/imgupload.aspx","Dialog Arguments Value","dialogHeight: 150px; dialogWidth: 330px; dialogTop: 200px; dialogLeft: 300px; edge: Raised; center: Yes; help: no; resizable:no; status: no;");
if (ret != null)
arg.value = ret;
}
OpenDialog(document.forms[0].all[\"imgID\"]);