UploaderControl and script callback problems in composite control

Sep 19, 2009 at 11:26 PM

Hey,

Great work on this control. It was quite straight-forward to integrate, and it works marvelously.

I'm embedding the UploaderControl in a composite control, and everything worked fine, except for the event handler scripts.

In the UploaderControl, because the embedded control ID in the Javascript was set to 'this.ID', the events weren't firing when the UploaderControl was in the composite control. I changed this to 'this.ClientID', and then I was able to receive Javascript events from the control when the control was a child in a composite control.

Is there any issue with this? 

Thanks.

 

            writer.Write(@"
<object id=""silverlight" + this.ClientID + @""" data=""data:application/x-silverlight-2,"" type=""application/x-silverlight-2"" width=""100%"" height=""100%"">
    <param name=""source"" value=""" + source + @"""/>
    <param name=""minRuntimeVersion"" value=""2.0.31005.0"" />
    <param name=""autoUpgrade"" value=""true"" />
    <param name=""initParams"" value=""" + sInitParams + @""" />
    <param name=""windowless"" value=""true"" />
    <param name=""onLoad"" value=""UploaderControl_onLoad_" + this.ClientID + @""" />
    <a href=""http://go.microsoft.com/fwlink/?LinkID=124807"" style=""text-decoration: none;"">
        <img src=""http://go.microsoft.com/fwlink/?LinkId=108181"" alt=""Get Microsoft Silverlight"" style=""border-style: none""/>
    </a>
</object>
<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
");
            string script = @"
function UploaderControl_onLoad_" + this.ClientID + @"() {
    UploaderControl.getInstance(""" + this.ClientID + @""").onLoad();
}
function UploaderControl_uploadStarted_" + this.ClientID + @"(sender, e) {
    UploaderControl.getInstance(""" + this.ClientID + @""").uploadStarted(sender, e);    
}
function UploaderControl_singleFileUploadFinished_" + this.ClientID + @"(sender, e) {
    UploaderControl.getInstance(""" + this.ClientID + @""").singleFileUploadFinished(sender, e);    
}
function UploaderControl_allFilesFinished_" + this.ClientID + @"(sender, e) {
    UploaderControl.getInstance(""" + this.ClientID + @""").allFilesFinished(sender, e);    
}
function UploaderControl_errorOccurred_" + this.ClientID + @"(sender, e) {
    UploaderControl.getInstance(""" + this.ClientID + @""").errorOccurred(sender, e);    
}
UploaderControl.getInstance(""" + this.ClientID + @""").initialize(" + (UserContext == null ? "null" : "\"" + UserContext + "\"") + @");
";
            csm.RegisterStartupScript(this.GetType(), this.ClientID, script, true);

 

 

Coordinator
Sep 20, 2009 at 3:09 AM

That should work just fine -- as long as the ID used for UploaderControl.getInstance matches the ID used to generate the javascript functions, you're set.