views:

36

answers:

0

Hi,

I am having a problem using the AJAX AsyncFileUpload control. I currently have a page that simply contains a textbox inside an UpdatePanel and the upload control itself just outside of it. I have written a JavaScript function called from the upload controls OnClientUploadComplete property which does a postback on the contents of the UpdatePanel. Subsequently the code tries to save the contents of the fileupload to a specific directory.

The problem is that an error is generated stating: "Object reference not set to an instance of an object.".

This error occurs on the line that tries to save the contents of the fileupload control. Strangely the file still gets uploaded to the correct directory. I'm not sure whether this has anything to do with an UpdatePanel being on the page.

Any suggestions as to why this is happening or any solutions would be greatly appreciated.

Here is my aspx code:

<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablepageMethods="true" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" OnLoad="UpdatePanel1_Load">
        <ContentTemplate>
            Asset Name:<asp:TextBox ID="Assetname" runat="server" Style="margin-bottom: 0px"></asp:TextBox><asp:Label
                ID="AnameErr" runat="server" Text="Label" Visible="false" ForeColor="Red"></asp:Label>
            <br />
            <asp:Label ID="Loading" runat="server" Visible="false">
                    Please Wait!<br /><br /><img src="images/wait.gif" alt="loading" /><br /><br />Upload in Progress!
            </asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnClientUploadComplete="postback" />
</div>
</form>

And the code behind:

protected void UpdatePanel1_Load(object sender, EventArgs e)
{
    valid = true;
    if (postback == false)
    {
        AnameErr.Text = "";
        String assetName = Assetname.Text; 
        if (assetName == "")               
        {
            valid = false;                
            AnameErr.Visible = true;
            AnameErr.Text = "*Please enter name for the asset";
        }
        if (valid == true)
        {
            Loading.Visible = true;
            strPath = Server.MapPath("~/Temp/") + assetName + ".wmv";
            AsyncFileUpload1.SaveAs(strPath);
            Debug.WriteLine(strPath);
        }
    }
}