|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis is an inherited button control which can perform file upload like in gmail manner. The button uses the inherited BackgroundI have searched for an article to perform GMail like file upload. It seems that we cannot perform file uploading using AJAX. I got some nice javascript from webtoolkit which was written to operate with PHP. The script uses the hidden Using the codeTo open the project, unzip it and open the file FileUploadControlTest.sln Open the file UploadButton.cs. The /// <summary />
/// Basic registration of events
/// </summary />
///
protected override void OnInit(EventArgs e)
{
this.Page.LoadComplete += new EventHandler(Page_LoadComplete);
base.OnInit(e);
this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(),
"ScriptBlock",
this.Page.ClientScript.GetWebResourceUrl(this.GetType(),
"WebControls.JScripts.AIMScript.js"));
string onsubmitstatement = "return AIM.submit(document.forms[0],
{'onStart' : " + OnStartScript + ",
'onComplete' : " + OnCompleteScript + "})";
this.Page.ClientScript.RegisterOnSubmitStatement(this.GetType(),
"OnSubmitScript", onsubmitstatement);
}
The /// <summary />
/// After completing page load, call the event handler on page to perform
/// operations on uploaded file
/// </summary />
///
///
void Page_LoadComplete(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
if (this.Parent.FindControl(RelatedFileUploadControlId) != null)
{
FileUpload fu =
this.Parent.FindControl(RelatedFileUploadControlId) as FileUpload;
UploadButtonEventArgs args = new UploadButtonEventArgs(fu);
UploadButtonEventHandler handler =
(UploadButtonEventHandler)Events[EventUploadClickKey];
if (handler != null)
{
try
{
WriteTextToClient(handler(this, args));
}
catch (System.Threading.ThreadAbortException ex)
{
// do nothing
}
catch (Exception ex)
{
WriteTextToClient("An exception occurred - " +
ex.Message);
}
}
else
{
WriteTextToClient("Handler not registered");
}
}
}
}
In the Points of InterestThe hidden IFRAME technique is an old one but in some complex situations, it will help us !!!
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||