Hi,
Please check this sample:
-
<%@ Page Language="C#" %>
-
-
<%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>
-
<%@ Import Namespace="CuteWebUI" %>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-
<script runat="server">
-
protected override void OnLoad(EventArgs e)
-
{
-
base.OnLoad(e);
-
-
if (!IsPostBack)
-
{
-
BindDetails();
-
}
-
}
-
-
private void BindDetails()
-
{
-
DetailsView1.DataSource = new DateTime[] { DateTime.Now };
-
DetailsView1.DataBind();
-
}
-
-
protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
-
{
-
UploadPersistedFile pf=(UploadPersistedFile)DetailsView1.FindControl("uploader1");
-
if (pf.File != null)
-
{
-
this.Title = "PageIndexChaging, saving " + pf.File.FileName;
-
}
-
-
DetailsView1.PageIndex = e.NewPageIndex;
-
BindDetails();
-
}
-
-
protected void uploader1_FileValidating(object sender, UploaderEventArgs args)
-
{
-
if (args.FileSize>1000000)
-
throw (new Exception(args.FileName+" is to big"));
-
}
-
-
protected void btnSubmit_Click(object sender, EventArgs e)
-
{
-
UploadPersistedFile pf = (UploadPersistedFile)DetailsView1.FindControl("uploader1");
-
if (pf.File != null)
-
{
-
//pf.File.CopyTo("NewFolder/"+pf.File.FileName);//MoveTo
-
labelMsg.Text = "File saved : " + pf.File.FileName;
-
}
-
else
-
{
-
labelMsg.Text = "No file!";
-
}
-
}
-
</script>
-
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head runat="server">
-
<title>Untitled Page</title>
-
<script type="text/javascript">
-
var uploader;
-
function CuteWebUI_AjaxUploader_OnInitialize()
-
{
-
uploader=this;
-
}
-
function CuteWebUI_AjaxUploader_OnPostback()
-
{
-
document.getElementById('<%=btnSubmit.ClientID %>').click();
-
return false;
-
}
-
function StartUpload()
-
{
-
if(uploader.getqueuecount()>0)
-
uploader.startupload();
-
else
-
alert("please select a file");
-
}
-
</script>
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div>
-
<asp:DetailsView runat="server" ID="DetailsView1" AllowPaging="True" OnPageIndexChanging="DetailsView1_PageIndexChanging">
-
<Fields>
-
<asp:TemplateField HeaderText="Attachment">
-
<ItemTemplate>
-
<CuteWebUI:UploadPersistedFile id="uploader1" ManualStartUpload="True" runat="server" ItemTextTemplate="{0} {1} " OnFileValidating="uploader1_FileValidating" />
-
</ItemTemplate>
-
</asp:TemplateField>
-
</Fields>
-
</asp:DetailsView>
-
<asp:Button runat=server id="btnSubmit" Text="Submit" Style="display:none;" OnClick="btnSubmit_Click" />
-
<button onclick="StartUpload();return false;">save profile</button>
-
<asp:Label runat=server ID="labelMsg" />
-
</div>
-
</form>
-
</body>
-
</html>
Regards,
Terry