ASP.NET网页的对话框交互。。-自己搞定了,散分。。(200分)

  • 主题发起人 蓝叶菱
  • 开始时间

蓝叶菱

Unregistered / Unconfirmed
GUEST, unregistred user!
C#.NET开发上传图片的程序
主窗口Default.aspx使用
var filename=showModalDialog("upfile.aspx")
这个函数进行接收弹出窗口进行接收信息。
upfile.aspx使用FileUpload进行上传。
<asp:FileUpload ID=&quot;FileUpload1&quot;
runat=&quot;server&quot;
CssClass=&quot;box1&quot;
Width=&quot;360px&quot;
/>
确定按钮代码过程是这样的:
1。先在数据库插入,取得标识(ID,自动编号),之后安装用户名返回一个id+文件名的图像文件。保证了不重复。。
2。之后使用RegisterXXXX,或者response.write(&quot;<script>window.returnValue&quot;+id.jpg<..script>
通过window.returnValue返回上传的文件名。
问题是:
[red]点击确定后,没有关闭这个窗口,又弹出了一个upfile.aspx,无法和主窗口交互[/red]default.aspx.
 
可以采用缓存来保存你要设计的信息,如:Session
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3566391
 
Session不能保存这个showModalDialog的信息。
 
asp.net有其它的对象可以保存你要的信息的。具体你查找一找,但是一定是可以保存你的信息的。
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3566391
 
加<base>语句就可以了。。。
问题自己解决了,散分。。。。。。。
 
能否把解决方式写的在详细些!?
谢谢!~~
 
接分,自力更生
 
详细说说
 
很简单。
答案是你使用的ASPX页面会自动POSTBACK.
只要在这个upfile.aspx的页面上加上<base语句就可以了。
<html>
<head>
....
<base target=&quot;_self&quot;>
<body>
....
</html>
源代码这样的,这个程序是一个HTMLEDIT。节选部分单元。
// Custom1(弹出命令)
else
if (cmdID == 'upfile') {//提出警告例子
var myTitle=&quot;上传图像&quot;;
var myText=window.showModalDialog(_editor_url+&quot;popups/upfile.aspx&quot;,
myTitle,
&quot;resizable: yes;
help: no;
status: no;
scroll: no;&quot;);
if (myText+&quot;xxxx&quot;)
{ editor_insertHTML(objname,myText);}
//alert(&quot;你好,我是一个自定义按钮&quot;);
}
//----弹出upfile.aspx
<%@ Page Language=&quot;C#&quot;
AutoEventWireup=&quot;true&quot;
CodeFile=&quot;upfile.aspx.cs&quot;
Inherits=&quot;include_popups_upfile&quot;
%>
<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>
<html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
style=&quot;width:360px;
Height: 60px;&quot;>
<head runat=&quot;server&quot;>
<base target=&quot;_self&quot;
/>
<title>上传图片</title>
<link href=&quot;../../include/popups/css.css&quot;
rel=&quot;stylesheet&quot;
type=&quot;text/css&quot;
/>
<script language=&quot;javascript&quot;
type=&quot;text/javascript&quot;>
// <!CDATA[
function btnCancle_onclick() {
window.close();
}
// ]]>
</script>
</head>
<body>
<form id=&quot;form1&quot;
runat=&quot;server&quot;>
<div>
<table style=&quot;width: 415px&quot;>
<tr>
<td style=&quot;width: 76px;
height: 26px;
text-align: right&quot;>
<span style=&quot;font-size: 10pt&quot;>图片文件:</span></td>
<td style=&quot;width: 107px;
height: 26px&quot;>
<asp:FileUpload ID=&quot;FileUpload1&quot;
runat=&quot;server&quot;
CssClass=&quot;button2&quot;
/>
</td>
</tr>
<tr>
<td colspan=&quot;2&quot;
style=&quot;height: 25px;
text-align: center;
background-color: #ccccff;&quot;>
<asp:Button ID=&quot;btnOk&quot;
runat=&quot;server&quot;
Text=&quot;上传&quot;
Width=&quot;69px&quot;
OnClick=&quot;btnOk_Click&quot;
CssClass=&quot;button2&quot;
/>
<input id=&quot;btnCancle&quot;
style=&quot;width: 65px&quot;
type=&quot;button&quot;
value=&quot;关闭&quot;
onclick=&quot;return btnCancle_onclick()&quot;
class=&quot;button2&quot;
/></td>
</tr>
</table>

</div>
</form>
</body>
</html>
-----upfile.aspx.cs程序。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Text;
public partial class include_popups_upfile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session[&quot;用户&quot;] == null)
{
Response.Write(&quot;<script>window.close();</script>&quot;);
}

}
protected void btnOk_Click(object sender, EventArgs e)
{

string FileExt = (Path.GetExtension(FileUpload1.FileName).ToLower());
if (&quot;.jpg&quot;
!= FileExt && &quot;.jpeg&quot;
!= FileExt)
{
Response.Write(&quot;<script language='javascript'>alert('对不起,你必须选择jpg图像文件!')</script>&quot;);
return;
}
if (Session[&quot;用户&quot;] == null)
{
return;
}
string connstr = System.Configuration.ConfigurationManager.AppSettings[&quot;xaHome&quot;];
SqlConnection conn = new SqlConnection(connstr);
SqlCommand qdml = new SqlCommand();
qdml.Connection = conn;
qdml.CommandType = CommandType.StoredProcedure;
qdml.CommandText = &quot;spAppendFile&quot;;
//-----参数赋值-----
qdml.Parameters.Add(&quot;@pUser&quot;, SqlDbType.VarChar).Value = Convert.ToString(Session[&quot;用户&quot;]);
qdml.Parameters.Add(&quot;@pFile&quot;, SqlDbType.VarChar).Value = FileExt;
SqlParameter ret = qdml.Parameters.Add(&quot;ret&quot;, SqlDbType.Int);
ret.Direction = ParameterDirection.ReturnValue;//返回值
qdml.Connection.Open();
qdml.ExecuteNonQuery();
//----开始保存图像----
if (null != FileExt)
{
string filename = Server.MapPath(&quot;~&quot;) + &quot;//files//&quot;
+ Convert.ToString(ret.Value) + FileExt;
FileUpload1.SaveAs(filename);
//----保存并且,返回确定对话框----
//string sImg = Convert.ToString(ret.Value) + FileExt;
string sImg = &quot;<img src=files////&quot;+Convert.ToString(ret.Value)+FileExt+&quot;>&quot;;
StringBuilder sbScript = new StringBuilder();
sbScript.Append(&quot;<script>/n&quot;);
sbScript.Append(&quot;window.returnValue=/&quot;&quot;
+ sImg + &quot;/&quot;;/n&quot;);
sbScript.Append(&quot;window.close();/n&quot;);
sbScript.Append(&quot;</script>/n&quot;);
string script = sbScript.ToString();
if (!ClientScript.IsClientScriptBlockRegistered(&quot;clientScript&quot;))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), &quot;clientscript&quot;, script);
// RegisterClientScriptBlock(&quot;clientScript&quot;, script);过时
}
}
}
protected void btnOk_Command(object sender, CommandEventArgs e)
{
}
}
 
自力更生啊
学习
 
谢谢啊!~
写的很详细啊!~~~
 
再来两个人。。。
 
我来了,到底有没有分呀,
 
再来一个,
 
我做过这种交互:从对话框中勾选多个选项,关闭后传递到调用它的页面中
 
强人都是自己搞定问题的
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
710
import
I
顶部