title: display gridview after upload file in AsyncFileUpload in updatepanel asp.net c#
body: <p>I want use AsyncFileUpload in updatepanel</p>
  
  <p>after uploaded file, I want display uploaded file in gridview.</p>
  
  <p>I use this method, but after upload I can't see gridview. Please help me to see my gridview.</p>
  
  <p>my scripts is:</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
      var ifIgnoreError = false;
      function uploadError(sender, args) {
           if (ifIgnoreError) {
              $get("&lt;%=lblStatus.ClientID%&gt;").style.color = "red";
              $get("&lt;%=lblStatus.ClientID%&gt;").innerHTML = " File not permitted ";
              alert("Allowed file is  .jpg ,.jpeg,.png,.gif   ");
          }
          else {
              alert(args.get_message());
          }
      }
  
      function StartUpload(sender, args) {
  
          var fileName = args.get_fileName();
          var fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);
          if (fileExtension == 'jpg' || fileExtension == 'jpeg' || fileExtension == 'png' || fileExtension == 'gif') {
  
              $get("&lt;%=lblStatus.ClientID%&gt;").style.color = "green";
              $get("&lt;%=lblStatus.ClientID%&gt;").innerHTML = "Uploading...";
          }
          else {           
              ifIgnoreError = true;
              sender._stopLoad();
          }
      }
  
  
      function UploadComplete(sender, args) {
         $get("&lt;%=lblStatus.ClientID%&gt;").style.color = "#33CCFF";
         $get("&lt;%=lblStatus.ClientID%&gt;").innerHTML = "The file was uploaded successfully";
  
  //If this code is uncomment, I can't see gridview            
  var btnClick = document.getElementById("btnClick"); 
          btnClick.click();
  
  
  //If this code uncomment, file uploaded twice
       //   __doPostBack('UpdatePanel1', '');
  
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>and html is :</p>
  
  <pre><code>&lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;
      &lt;/asp:ScriptManager&gt;
  
      &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"&gt; 
         &lt;Triggers&gt;       
          &lt;asp:AsyncPostBackTrigger ControlID="btnClick" EventName="Click" /&gt;    
           &lt;/Triggers&gt;
      &lt;ContentTemplate&gt;
         &lt;asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" ClientIDMode="AutoID"                                        
  OnClientUploadComplete="UploadComplete" OnClientUploadError="uploadError" 
  OnClientUploadStarted="StartUpload"  ErrorBackColor="#66CCFF"                                        onuploadedcomplete="AsyncFileUpload1_UploadedComplete" ThrobberID="Throbber" 
  UploaderStyle="Traditional" UploadingBackColor="#66CCFF" Width="400px" /&gt;
  
   &lt;asp:Button runat="server" ID="btnClick" Text="Update grid" style="display:none"/&gt;
  
  
  &lt;asp:Label ID="Throbber" runat="server"&gt;
  &lt;img src="../../images/Pages/loading19.gif" align="absmiddle" alt="loading" /&gt;             
  &lt;/asp:Label&gt;
  &lt;asp:Label ID="lblStatus" runat="server"     Style="font-family: tahoma; font-size: 11px;"&gt;&lt;/asp:Label&gt;
  
    &lt;asp:GridView ID="GrdMadarek" AutoGenerateColumns="false" runat="server"&gt;
      &lt;Columns&gt;
      &lt;asp:TemplateField&gt;
      &lt;ItemTemplate&gt;
          &lt;asp:Image ID="ImgMadarek" runat="server"  Width="50px" Height="40px" ImageUrl='&lt;%#Eval("MadrakFileName","~/files/{0}")%&gt;'/&gt;
      &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField&gt;
      &lt;ItemTemplate&gt;
          &lt;asp:LinkButton ID="lnkBtnDelMadrek" runat="server"&gt;delete&lt;/asp:LinkButton&gt;
      &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
    &lt;/asp:GridView&gt;
       &lt;/ContentTemplate&gt;
       &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>and code in aspx.cs is :</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {      
          if (Request.Params.Get("__EVENTTARGET") == "UploadPostback")
          {
  
          }
          else
          {
              if (AsyncFileUpload1.HasFile)
              {
                  string FinalFileName = Path.GetExtension(AsyncFileUpload1.FileName);
                  string strPath = MapPath("~/files/") + FinalFileName;
                  AsyncFileUpload1.SaveAs(strPath);
  
  
                  if (Session["MadarekList"] != null)
                  {
                      var MadarekList = (List&lt;MadrakDetails&gt;)Session["MadarekList"];
                      MadrakDetails Madrak = new MadrakDetails();
                      Madrak.MadrakFileName = FinalFileName;
                      MadarekList.Add(Madrak);
                      Session["MadarekList"] = MadarekList;
                      GrdMadarek.DataSource = MadarekList;
                      GrdMadarek.DataBind();
                        }
                  else
                  {
                      var MadarekList = new List&lt;MadrakDetails&gt;();
                      MadrakDetails Madrak = new MadrakDetails();
                      Madrak.MadrakFileName = FinalFileName;
                      MadarekList.Add(Madrak);
                      Session["MadarekList"] = MadarekList;
                      GrdMadarek.DataSource = MadarekList;
                      GrdMadarek.DataBind();
                  }
              }
          }
      }
  
  public class MadrakDetails
      {
          string madrakFileName = string.Empty;
  
          public string MadrakFileName
          {
              get { return madrakFileName; }
              set { madrakFileName = value; }
          }
  
      }
      protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
      {
      //   no code here
      }
  </code></pre>