0

I'm trying to display a warning dialogue if the filename length is too long within an AjaxFileUpload_UploadComplete method. I can easily do the logic to count characters but how am I supposed to display a warning dialogue or access the built in warning messages? I can't call a javascript dialogue or display a label since AJAX requests are performed independently of the ASP.NET page infrastructure, and any changes made to controls' state are not visible.

protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            //Count characters in filename.
            var filenameChars = e.FileName.ToString();
            if (filenameChars.Length > 10)
            {
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myFunction", "MyFunction();", true);
                return;
             }
         }

In the example, the JavaScript dialogue does not appear and I have not way to display a warning..

Shane
  • 522
  • 1
  • 6
  • 22
  • instead of RegisterStartupScript try using RegisterClientScript – Kevin Shah Apr 24 '19 at 14:41
  • @KevinShah I tried your suggestion but that didn't work either. `string script = string.Format(@" myFunction()"); ScriptManager.RegisterClientScriptBlock(this, typeof(Page), MyFunction, script, true);` – Shane Apr 24 '19 at 14:53

0 Answers0