我有一个正在处理的页面,我正在将多个用户控件链接到。用户控件包含 3 个按钮,一个附加、清除和查看按钮。当用户单击页面上的任何控件时,结果信息将“转储”到页面上最后一个可见控件中。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" MasterPageFile="DefaultPage.master" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register tagName="FileHandler" src="FileHandling.ascx" tagPrefix="ucFile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
<asp:UpdatePanel ID="upPanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
<ucFile:FileHandler ID="fFile1" runat="server" />
</td>
<td>
<ucFile:FileHandler ID="fFile2" runat="server" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
所有文件处理和处理都在控件内处理,当通过生成的文件名完成上传到文件服务器时会发生一个事件。单击任一按钮时,文件名始终存储在最后一个控件的文本框中的控件内部。控制代码:
<table style="width: 50%;">
<tr style="white-space: nowrap;">
<td style="width: 1%;">
<asp:Label runat="server" ID="lblFile" />
</td>
<td style="width: 20%;">
<asp:TextBox ID="txtFile" CssClass="backColor" runat="server" OnTextChanged="FileInformationChanged" />
</td>
<td style="width: 1%">
<%--<asp:Button runat="server" ID="btnUpload" CssClass="btn" Text="Attach" OnClick="UploadFile"/>--%>
<input type="button" id="btnUpload" class="btn" tabindex="30" value="Attach" onclick="SetupUpload();" />
</td>
<td style="width: 1%">
<%--<asp:Button runat="server" ID="btnClear" Text="Clear" CssClass="btn" OnClick="ClearTextValue"/>--%>
<input type="button" id="btnClearFile" class="btn" value="Clear" onclick="document.getElementById('<%=txtFile.ClientID%>').value = '';document.getElementById('<%=hfFile.ClientID%>').value = '';" />
</td>
<td style="width: 1%">
<a href="#here" onclick="ViewLink(document.getElementById('<%=hfFile.ClientID%>').value, '')">View</a>
</td>
<td style="width: 1%">
<asp:HiddenField ID="hfFile" runat="server" />
</td>
</tr>
</table>
<script type="text/javascript">
var ItemPath = "";
function SetupUpload(File) {
ItemPath = File;
VersionAttach('<%=UploadPath%>', 'true');
}
function UploadComplete(File) {
document.getElementById('<%=txtFile.ClientID%>').value = File.substring(File.lastIndexOf("/") + 1);
document.getElementById('<%=hfFile.ClientID%>').value = File;
alert('<%=txtFile.Text %>');
alert('<%=ClientID %>')
}
function ViewLink(File, Alert) {
if (File != "") {
if (File.indexOf("../data/") != -1) {
window.open(File, '_blank');
}
else {
window.open('../data/<%=UploadPath%>/' + File, '_blank');
}
}
else if (Alert == "") {
alert('No file has been uploaded for this field.');
}
}
</script>