Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Unable to modify sibling controls' properties in an AsyncFileUpload event handler

$
0
0

I have an AsyncFileUpload, an ImageButton, and a TextBox wrapped into a .ascx user control, which contains an UpdatePanel itself holding the above to carry out partial update in a table cell. Simplified by taking out some layout code and it's straightforward enough:

<form id="form1" enctype="multipart/form-data" runat="server"><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><uc1:ResourceCellControl runat="server" ID="ResourceCellControl" /></form>

And the .ascx markup:

<asp:UpdatePanel ID="UpdatePanelListViewCell" runat="server"><ContentTemplate><asp:ImageButton ID="UploadImgBtn" runat="server" Height="40px" OnClick="UploadImgBtn_Click" Width="40px" /><asp:TextBox ID="TBURL" runat="server" Height="12px" Width="95%" Font-Size="X-Small" AutoPostBack="True" ClientIDMode="AutoID" OnTextChanged="TBURL_TextChanged"></asp:TextBox><ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload" runat="server" OnUploadedComplete="AsyncFileUpload_UploadedComplete" /></ContentTemplate><Triggers>        <asp:AsyncPostBackTrigger ControlID="TBURL" EventName="TextChanged" /><asp:AsyncPostBackTrigger ControlID="UploadImgBtn" /></Triggers></asp:UpdatePanel>

The whole idea is when the upload is complete, show a new filename renamed from the original uploaded one in the Textbox and replace the src of ImageButton with the location of the uploaded file (with another intent of clicking it to open a new window to show the uploaded image in full), so I tried to utilize the OnUploadedComplete event handler:

    protected void AsyncFileUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
    {       

        var afu = sender as AsyncFileUpload;
        if (afu.HasFile)
        {
            TextBox tb = afu.Parent.FindControl("TBURL") as TextBox;

            string fileExtension = System.IO.Path.GetExtension(afu.FileName);
            int found = validExts.Where(result => result == fileExtension).Count();

            if (found == 0)
            {
                tb.Text = "Valid file types: " + validExts;
            }
            else
            {
                tb.Text = afu.FileName;				
            }

            UploadImgBtn.AlternateText = "Hello";

            //UpdatePanelListViewCell.Update();
        }
    }

However, with the above experimental code, I found the properties from the sibling controls,  such as TextBox.Text and the UploadImgBtn.AlternateText, cannot be modified, despite both of them can be accessed and their properties can be modified when the debugger is tracing through them, after that their values are still not changed on the page. I also tried to add a Click event handler to ImageButton to change its alternate text, it worked, so I guess there are some special mechanism or issues on AsyncFileUpload to prevent such behaviors. Anyone knows how to modify sibling controls' properties in an AsyncFileUpload event handler or any workarounds? Thanks.


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>