在UpdatePanel上使用FileUpload上传文件 (asp.net C#)
首先我很遗憾的告诉大家,因为微软的偷懒,目前UpdatePanel还不支持文件上传。变相的解决办法就是UpdatePanel中设置PostBackTrigger:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="上传" OnClick="Button1_Click" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
而如果你又想在这个UpdatePanel上做点花样,比如加了一个asp:Panel, 可以通过按钮事件触发隐藏或显示的,你会发现FileUpload1并不能找到文件。。。
其实道理很简单,UpdatePanel中的内容是通过XmlHttp实时填充的,在你让他显示之前,查看页面源代码里面是空的。一个动态控件更新
普通数据没问题,但上传文件就不行了,我的解决办法是用普通div代替asp:Panel,并写了2个函数来动态发送控制脚本,按钮事件中只要调用该函数
即可:
<div id="Panel1"></div>
private void ShowPanel()
{
string script = "document.getElementById('Panel1').style.display='';";
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ShowPanel", script, true);
}
private void ClosePanel()
{
string script = "document.getElementById('Panel1').style.display='none';";
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ClosePanel", script, true);
}
相关文档:
1 示例xml文件 model.xml
<?xml version="1.0" encoding="utf-8" ?>
<DrRoot>
<SiteName>xml操作示例</SiteName>
<SiteUrl>www.abc.com.cn</SiteUrl>
.net开源论坛
<SiteKeyWord>xml操作示例</SiteKeyWord>
<FileType>gif|jpg| ......
1)创建txt文件【web.config】
--------------------------------------------------------------------
<appSettings>
<add key="EditChars" value="D:\Site\ZJPS\TextFile\EditChars.txt"/>
</appSettings>
2) 页面的CS文件中:
----------------- ......
下面以Test 站点为例,说明一下如何设置 .net framework 2.0 aspnet_isapi 的 IIS 设置
按如下步骤操作即可
1、打开站点,右击属性,找到主目录(本示例是以虚拟目录,服务器版本请找主目录)
打开如下图所示的窗口
......
using System;
using System.IO;
namespace WriteLog
{
/// <summary>
/// WriteInLog 的摘要说明。
/// </summary>
public class WriteInLog
......