<add tagPrefix="anthem" namespace="Anthem" assembly="Anthem"/>
Anthem.NET提供了一套自己就带有Ajax功能的、继承于现有ASP.NET控件的服务器端控件。根据上面在web.config文件中的注册,这部分控件的前缀为anthem。
<body>
<form id="form1" runat="server">
<fieldset>
<legend>Default ASP.NET FileUpload</legend>
<asp:FileUpload ID="defaultFileUpload" runat="server" />
<asp:Button ID="defaultUploadButton" runat="server" OnClick="defaultUploadButton_Click" Text="Upload" />
<asp:Label ID="defaultResultLabel" runat="server" Text=""></asp:Label>
</fieldset>
<fieldset>
<legend>Anthem.NET FileUpload</legend>
<anthem:FileUpload ID="anthemFileUpload" runat="server" />
<anthem:Button ID="anthemUploadButton" TextDuringCallBack="uploading" EnabledDuringCallBack="false"
runat="server" Text="Upload" OnClick="anthemUploadButton_Click" />
<anthem:Label ID="anthemResultLabel" runat="server" Text=""></anthem:Label>
</fieldset>
</form>
</body>
<form id="form1" runat="server">
<fieldset>
<legend>Default ASP.NET FileUpload</legend>
<asp:FileUpload ID="defaultFileUpload" runat="server" />
<asp:Button ID="defaultUploadButton" runat="server" OnClick="defaultUploadButton_Click" Text="Upload" />
<asp:Label ID="defaultResultLabel" runat="server" Text=""></asp:Label>
</fieldset>
<fieldset>
<legend>Anthem.NET FileUpload</legend>
<anthem:FileUpload ID="anthemFileUpload" runat="server" />
<anthem:Button ID="anthemUploadButton" TextDuringCallBack="uploading" EnabledDuringCallBack="false"
runat="server" Text="Upload" OnClick="anthemUploadButton_Click" />
<anthem:Label ID="anthemResultLabel" runat="server" Text=""></anthem:Label>
</fieldset>
</form>
</body>
后台代码:
//传统方式上传
protected void defaultUploadButton_Click(object sender, EventArgs e)
{
string FileName = defaultFileUpload.FileName; //上传文件名
int i = FileName.LastIndexOf(".");
string FileEx = FileName.Substring(i); //文件扩展名.jpg
string SaveFileName = string.Format("default{0}{1}{2}{3}",DateTime.Now.ToShortDateString(),DateTime.Now.Millisecond.ToString(),defaultFileUpload.FileBytes.Length.ToString() , FileEx);
defaultFileUpload.PostedFile.SaveAs(Server.MapPath("upload\\" + SaveFileName));
defaultResultLabel.Text = string.Format("File \"{0}\" uploaded ({1} bytes,{2}).",
defaultFileUpload.FileName,
defaultFileUpload.FileBytes.Length,
SaveFileName
);
}
//anthem方式上传
protected void anthemUploadButton_Click(object sender, EventArgs e)
{
string FileName = anthemFileUpload.FileName;
int i = FileName.LastIndexOf(".");
string FileEx = FileName.Substring(i);
string SaveFileName = string.Format("anthem{0}{1}{2}{3}", DateTime.Now.ToShortDateString(), DateTime.Now.Millisecond.ToString(), anthemFileUpload.FileBytes.Length.ToString(), FileEx);
anthemFileUpload.PostedFile.SaveAs(Server.MapPath("upload\\"+SaveFileName));
anthemResultLabel.Text = string.Format("File \"{0}\" uploaded ({1} bytes,{2}).",
anthemFileUpload.FileName,
anthemFileUpload.FileBytes.Length,
SaveFileName
);
anthemResultLabel.UpdateAfterCallBack = true;
}
protected void defaultUploadButton_Click(object sender, EventArgs e)
{
string FileName = defaultFileUpload.FileName; //上传文件名
int i = FileName.LastIndexOf(".");
string FileEx = FileName.Substring(i); //文件扩展名.jpg
string SaveFileName = string.Format("default{0}{1}{2}{3}",DateTime.Now.ToShortDateString(),DateTime.Now.Millisecond.ToString(),defaultFileUpload.FileBytes.Length.ToString() , FileEx);
defaultFileUpload.PostedFile.SaveAs(Server.MapPath("upload\\" + SaveFileName));
defaultResultLabel.Text = string.Format("File \"{0}\" uploaded ({1} bytes,{2}).",
defaultFileUpload.FileName,
defaultFileUpload.FileBytes.Length,
SaveFileName
);
}
//anthem方式上传
protected void anthemUploadButton_Click(object sender, EventArgs e)
{
string FileName = anthemFileUpload.FileName;
int i = FileName.LastIndexOf(".");
string FileEx = FileName.Substring(i);
string SaveFileName = string.Format("anthem{0}{1}{2}{3}", DateTime.Now.ToShortDateString(), DateTime.Now.Millisecond.ToString(), anthemFileUpload.FileBytes.Length.ToString(), FileEx);
anthemFileUpload.PostedFile.SaveAs(Server.MapPath("upload\\"+SaveFileName));
anthemResultLabel.Text = string.Format("File \"{0}\" uploaded ({1} bytes,{2}).",
anthemFileUpload.FileName,
anthemFileUpload.FileBytes.Length,
SaveFileName
);
anthemResultLabel.UpdateAfterCallBack = true;
}