title: How to trigger a rebind of gridview from javascript or jQuery on markup page?
body: <p>Is there a way to trigger a GridView rebind from an html markup page using jQuery or jscript? </p>
  
  <p>I have an ActiveX download control which passes all events via jscript. </p>
  
  <p>So, a have a download complete event on the markup page but not the code behind. </p>
  
  <p>Here is the main aspx page:</p>
  
  <pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server"&gt;
  
  &lt;script type="text/javascript" src="aurigma\iuembed.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          function FileDownloader_DownloadStep(Step){
          //The file list is going to be downloaded - "2 = About to Start" 
          if (Step == 2){
              //Dynamically build the filelist for the downloader
              getFileDownloader("FileDownloader").setFileList("GetFileList.aspx");
          }
          //The user has confirmed the download - "6 = File Download About to Start"
          if (Step == 6){
              //Perform the initialization updates to the first file only
              var xmlhttp; 
              if (typeof XMLHttpRequest != 'undefined') { 
                  xmlhttp = new XMLHttpRequest(); 
              } 
              if (!xmlhttp) { 
                  throw "Browser doesn't support XMLHttpRequest."; 
              } 
              var data = ""; 
              xmlhttp.open("POST", "UpdateVideoInitiated.aspx", true); 
              //Send the proper header information along with the request 
              xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
               //xmlhttp.setRequestHeader("Content-length", data.length); 
              xmlhttp.setRequestHeader("Connection", "close"); 
              xmlhttp.send(data); 
          }
      }
          function onDownloadItemComplete(Result, ErrorPage, Url, FileName, ContentType, FileSize){
              var xmlhttp;
              var data;
  
              //The handler will display the error description or updates as noted
              switch (Result){
                          //Update the completed file as complete and then perform initialization updates to the next file only
                  case 1: if (typeof XMLHttpRequest != 'undefined') { 
                              xmlhttp = new XMLHttpRequest(); 
                          } 
                          if (!xmlhttp) { 
                              throw "Browser doesn't support XMLHttpRequest."; 
                          } 
                          data = FileName; 
                          xmlhttp.open("POST", "UpdateVideoDownloaded.aspx?FileName=" + FileName + "&amp;FileSize=" + FileSize, true); 
                          //Send the proper header information along with the request 
                          xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
                           //xmlhttp.setRequestHeader("Content-length", data.length); 
                          xmlhttp.setRequestHeader("Connection", "close"); 
                          xmlhttp.send(data); 
                          break;
                  case 2: alert("An error has occurred while downloading the file " + FileName);
                          break;
                          //Update any skipped files to back off the initialization updates to the passed file only
                  case 3: if (typeof XMLHttpRequest != 'undefined') { 
                              xmlhttp = new XMLHttpRequest(); 
                          } 
                          if (!xmlhttp) { 
                              throw "Browser doesn't support XMLHttpRequest."; 
                          } 
                          data = FileName; 
                          xmlhttp.open("POST", "UpdateVideoSkipped.aspx?FileName=" + FileName, true); 
                          //Send the proper header information along with the request 
                          xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
                           //xmlhttp.setRequestHeader("Content-length", data.length); 
                          xmlhttp.setRequestHeader("Connection", "close"); 
                          xmlhttp.send(data); 
                          break;        
                  case 4: alert("The server returned a wrong MIME type (should be " + ContentType + ") for the file " + FileName);
                          break;
                  case 5: alert("The server returned a wrong size (should be " + FileSize + ") for the file " + FileName);
                          break;
                  case 6: alert("An error has occurred while writing the file " + FileName + " to disk");
                          break;
                  case 7: alert("The file " + FileName + " could not be found on the " + "server");
                          break;
                  case 8: alert("Access to the file " + FileName + " denied");
                          break;
                  case 9: alert("Time out while downloading the file " + FileName);
                          break;
              }
          }
          function onDownloadComplete(Result){
              //The handler will display the error description
              switch (Result){
                          //Update the member download statistics and rebind the grid??? 
                  case 0: if (typeof XMLHttpRequest != 'undefined') { 
                              xmlhttp = new XMLHttpRequest(); 
                          } 
                          if (!xmlhttp) { 
                              throw "Browser doesn't support XMLHttpRequest."; 
                          } 
                          data = ""; 
                          xmlhttp.open("POST", "UpdateDownloadsComplete.aspx", true); 
                          //Send the proper header information along with the request 
                          xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
                           //xmlhttp.setRequestHeader("Content-length", data.length); 
                          xmlhttp.setRequestHeader("Connection", "close"); 
                          xmlhttp.send(data); 
                          break;
                  case 1: alert("An error has occurred while creating the file list");
                          break;        
                  case 2: alert("An error has occurred while downloading the file list");
                          break;
                  case 3: alert("The file list is empty");
                          break;
                  case 7: alert("The file list could not be found on the server");
                          break;
                  case 8: alert("Access to the file list denied");
                          break;
                  case 9: alert("Time out while downloading the file list");
                          break;
              }
          }
  &lt;/script&gt;
  
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"&gt;
  
  &lt;div class="borderDiv"&gt;
       &lt;table cellspacing="0" class="borderTable0" width="100%"&gt;
           &lt;tr&gt;
              &lt;td class="Subhdr" &gt;
                  &lt;asp:label id="lblScreenHeader" Cssclass="ScreenHdr" runat="server" Height="24px"&gt;Member Video Download Detail&lt;/asp:label&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;div class="NinetyNine5PercentWide SolidThreePixelBorder" style="background-color:White"&gt;
          &lt;div class="OneHundredPercentWide EightPixelTopMargin TenPixelBottomMargin"&gt;
              &lt;div class="FileListHdr"&gt;
                  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                  &lt;span&gt;Current Escrow Balance (Available for Future Use):&lt;/span&gt;
                  &amp;nbsp;&amp;nbsp;
                  &lt;asp:label ID="lblAvailableBalance" Cssclass="FileListHdr" runat="server" &gt;$280.00&lt;/asp:label&gt;
                  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                  &lt;asp:label ID="lblAvailableBalanceMessage" Cssclass="FileListHdr" runat="server" &gt;&lt;/asp:label&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="NinetyNinePercentWide"&gt;
              &lt;div class="FileListHdr EightPixelBottomMargin"&gt;
                  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                  &lt;span class="FileListHdr" &gt;Number of Files Selected for Download:&lt;/span&gt;
                  &amp;nbsp;
                  &lt;asp:label ID="lblTotalFiles" Cssclass="FileListHdr" runat="server" &gt;&lt;/asp:label&gt;
                  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                  &lt;span class="FileListHdr" &gt;Total MBytes:&lt;/span&gt;
                  &amp;nbsp;
                  &lt;asp:label ID="lblTotalMBytes" Cssclass="FileListHdr" runat="server" &gt;&lt;/asp:label&gt;
                  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                  &lt;span class="FileListHdr" &gt;Estmated Download Time:&lt;/span&gt;
                  &amp;nbsp;
                  &lt;asp:label ID="lblEstimatedTime" Cssclass="FileListHdr" runat="server" &gt;&lt;/asp:label&gt;
              &lt;/div&gt; 
          &lt;/div&gt;
          &lt;div class="NinetyNinePercentWide"&gt;
              &lt;div class="OneHundredPercentWide"&gt;
                  &lt;div class="DivDownload" &gt;
                      &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                      &lt;script type="text/javascript"&gt;
                          //Create JavaScript object that will embed File Downloader to the page
                          var fd = new FileDownloaderWriter("FileDownloader", 170, 28);
  
                          //For ActiveX control full path to CAB file (including file name) should be specified
                          fd.activeXControlCodeBase = "aurigma/FileDownloader2.cab";
                          fd.activeXControlVersion = "2,0,16,0";
  
                          //Set the Download button text
                          fd.addParam("ButtonDownloadText", "DOWNLOAD NOW");
  
                          //Set the Download button background color
                          //fd.addParam("BackgroundColor", "#E0EBFF");
                          fd.addParam("BackgroundColor", "White");
  
                          //Set the Download button regular image
                          fd.addParam("ButtonDownloadImageFormat", "width=170;height=28;BackgroundColor=White;" + 
                              "urlNormal=App_Themes/Default/images/BtnDownload.jpg;" +
                              "urlHover=App_Themes/Default/images/BtnHover.jpg;" +
                              "urlPressed=App_Themes/Default/images/BtnPressed.jpg;" +
                              "urlDisabled=App_Themes/Default/images/BtnPressed.jpg");
  
                          //Set license key 
                          fd.addParam("LicenseKey", "13550-77033-55676-789DB-8332");
  
                          //Set reconnect attampts count
                          fd.addParam("ReconnectAttemptsCount", "360");
  
                          //Set reconnect timeout value (30000 = 10 seconds)
                          fd.addParam("ReconnectTimeOut", "10000");
  
                          //The following listener will perform some actions when the file list is about to be downloaded
                          fd.addEventListener("DownloadStep", "FileDownloader_DownloadStep");
  
                          //The following listener will perform some actions when download of a single file is finished
                          fd.addEventListener("DownloadItemComplete", "onDownloadItemComplete");
  
                          //The following listener will perform some actions when download process is complete
                          fd.addEventListener("DownloadComplete", "onDownloadComplete");
  
                          //The following listener will perform some actions when a general error is detected
                          //fd.addEventListener("Error", "onError");
  
                          //Add page load listener
                          //fd.fullPageLoadListenerName = "fullPageLoad";
  
                          //Set instructions property
                          fd.instructionsEnabled = true;
  
                          //Tell File Downloader writer object to generate all necessary HTML code to embed File Downloader into the page
                          fd.writeHtml();
                      &lt;/script&gt;
                   &lt;/div&gt; 
                   &lt;div class="FileListHdr"&gt;
                      &lt;asp:RadioButtonList id="rblMemberMachine" runat="server" Font-Bold="True" BackColor="White" ToolTip="Please select machine for downloading" 
                              CssClass="Radio FileListHdr" RepeatDirection="Horizontal" textAlign="right" BorderStyle="None"
                              AutoPostBack="True" OnSelectedIndexChanged="rblMemberMachine_SelectedIndexChanged" &gt;
                              &lt;asp:ListItem Text="Machine 1" Value="1" Selected="True"&gt;&lt;/asp:ListItem&gt;
                              &lt;asp:ListItem Text="Machine 2" Value="2"&gt;&lt;/asp:ListItem&gt;
                              &lt;asp:ListItem Text="Machine 3" Value="3"&gt;&lt;/asp:ListItem&gt;
                      &lt;/asp:RadioButtonList&gt;
                   &lt;/div&gt;
               &lt;/div&gt;
            &lt;/div&gt;
         &lt;/div&gt;
      &lt;div class="OneHundredPercentWide" &gt;
          &lt;asp:Panel ID="Panel1" runat="server" Width="100%" &gt;
              &lt;asp:GridView id="grvSessionOrderDownloads" runat="server" BorderWidth="2px" BorderStyle="Solid" BorderColor="#C0C0FF"
                  Font-Names="Arial" Font-Bold="True" Font-Size="8pt" GridLines="Horizontal" AutoGenerateColumns="False" 
                  HorizontalAlign="Left" ForeColor="Blue" CellPadding="2" AllowSorting="True" Width="100%"
                  OnRowDataBound="grvSessionOrderDownloads_OnRowDataBound" &gt;
  
                  &lt;HeaderStyle Font-Names="Arial" HorizontalAlign="Center" ForeColor="White" BackColor="#152EE5" 
                      CssClass="sessionOrderDownloadHeaders" Font-Size="Medium" /&gt;
                  &lt;RowStyle BackColor="White" ForeColor="#333333" /&gt;
                  &lt;AlternatingRowStyle BackColor="#A5B0FF" /&gt;
  
                  &lt;Columns&gt;
                      &lt;asp:BoundField Visible="False" DataField="SORD_ID" HeaderStyle-Width="0px" &gt;
                          &lt;HeaderStyle Width="0px" /&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:TemplateField HeaderStyle-Width="0px" &gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:CheckBox Visible="False" Enabled="false" ID="HiddenCheckBox" runat="server"
                                   Checked='&lt;%# Eval("SORD_SelectedForDownloadFlag") %&gt;' /&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;HeaderStyle Width="0px" /&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField HeaderText="Select Files" HeaderStyle-ForeColor="White" &gt; 
                          &lt;ItemTemplate &gt;
                              &amp;nbsp;&amp;nbsp;&amp;nbsp;
                              &lt;asp:ImageButton id="btnSelectVideo" runat="server" CommandArgument='&lt;%# Eval("SORD_ID") %&gt;' 
                                   CommandName="CheckUncheckVideo" ImageUrl='&lt;%# GetCheckboxImage(Container.DataItem) %&gt;' 
                                   Enabled='&lt;%# Eval("SORD_EnableSelectionCheckBox") %&gt;'
                                   Visible='&lt;%# Eval("SORD_EnableSelectionCheckBox") %&gt;'/&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;HeaderStyle Width="4%" /&gt;
                          &lt;ItemStyle VerticalAlign="Bottom" /&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:BoundField DataField="SORD_OSTA_ID" ReadOnly="True" HeaderStyle-ForeColor="White"
                          HeaderText="Status"&gt;
                          &lt;HeaderStyle Width="6%" /&gt;
                          &lt;ItemStyle CssClass="sessionOrderDownloadItems" /&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField DataField="SORD_Topic" ReadOnly="True" HeaderStyle-ForeColor="White"
                          HeaderText="General &lt;br /&gt; Topic" HtmlEncode="false" &gt;
                          &lt;HeaderStyle Width="15%" /&gt;
                          &lt;ItemStyle CssClass="sessionOrderDownloadItems" /&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField DataField="SORD_Session" ReadOnly="True" HeaderStyle-ForeColor="White"
                          HeaderText="Session &lt;br /&gt; YYMMDD" HtmlEncode="false" DataFormatString="{0:00-00-00}" &gt;
                          &lt;HeaderStyle Width="6%" /&gt;
                          &lt;ItemStyle CssClass="sessionOrderDownloadItems" /&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField DataField="SORD_FileExtension" ReadOnly="True" HeaderStyle-ForeColor="White"
                          HeaderText="File &lt;br /&gt; Type" HtmlEncode="false" &gt;
                          &lt;HeaderStyle Width="5%" /&gt;
                          &lt;ItemStyle CssClass="sessionOrderDownloadItems" /&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField DataField="SORD_SessionTitle" ReadOnly="True" HeaderStyle-ForeColor="White"
                          HeaderText="Presentation's Video-Title &lt;br /&gt; &amp;nbsp;&amp;nbsp; (or) Support-File Name" HtmlEncode="false" &gt;
                          &lt;HeaderStyle Width="29%" /&gt;
                          &lt;ItemStyle CssClass="sessionOrderDownloadItems" /&gt;
                      &lt;/asp:BoundField&gt;   
                      &lt;asp:BoundField DataField="SORD_VideoUnlockKey" ReadOnly="True" HeaderStyle-ForeColor="White" 
                          HeaderText="File Unlock &lt;br /&gt; Password" HtmlEncode="false" &gt;
                          &lt;HeaderStyle Width="15%" /&gt;
                          &lt;ItemStyle CssClass="sessionOrderDownloadItems" /&gt;
                      &lt;/asp:BoundField&gt;  
                      &lt;asp:BoundField DataField="SORD_LastDownloadDate"  
                          ReadOnly="True" HeaderStyle-ForeColor="White" HeaderText="Last &lt;br /&gt; Download" htmlEncode="False"
                          DataFormatString="{0:d}" &gt;
                          &lt;HeaderStyle Width="10%" /&gt;
                          &lt;ItemStyle CssClass="sessionOrderDownloadItems" /&gt;
                      &lt;/asp:BoundField&gt;   
                      &lt;asp:BoundField DataField="SORD_RemainingDownloads"  
                          ReadOnly="True" HeaderStyle-ForeColor="White" HeaderText="Remaining &lt;br /&gt; Downloads" htmlEncode="False" DataFormatString="{0:##0}" &gt;
                          &lt;HeaderStyle Width="10%" /&gt;
                          &lt;ItemStyle CssClass="sessionOrderDownloadItems" /&gt;
                      &lt;/asp:BoundField&gt;
                  &lt;/Columns&gt;
  
              &lt;/asp:GridView&gt;
          &lt;/asp:Panel&gt;
      &lt;/div&gt;
  &lt;/div&gt; 
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;
  &lt;asp:Label ID="Errormsg" runat="server" ForeColor="#CC0000"&gt;&lt;/asp:Label&gt;
  
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>And then here is the code behind (with basics):</p>
  
  <pre><code>Imports System
  Imports System.Data
  Imports System.Data.SqlClient
  Imports System.Text
  Imports System.Text.RegularExpressions
  Imports System.Security.Permissions
  Imports System.IO
  Imports System.Net
  
  Partial Class MemberVideoDownloads
  Inherits System.Web.UI.Page
  Dim strConnection As String = ConfigurationManager.ConnectionStrings("MYTest").ConnectionString
  Dim cnnSQL As SqlConnection
  Dim cmdSQL As SqlCommand
  Dim dadSQL As SqlDataAdapter
  'Member table
  Dim dtMember As New DataTable
  Dim drMember As DataRow
  'Session Order table
  Dim dtSessionOrder As New DataTable
  Dim drSessionOrder As DataRow
  'Member Order table for download
  Dim dtSessionOrdersForDownload As New DataTable
  Dim drSessionOrdersForDownload As DataRow
  Dim dvSessionOrdersForDownload As DataView
  'Session Folder table
  Dim dtSessionFolder As New DataTable
  Dim drSessionFolder As DataRow
  'Session Detail table
  Dim dtSessionDetail As New DataTable
  Dim drSessionDetail As DataRow
  'Session Orders Selected table
  Dim dtSessionOrdersSelected As New DataTable
  Dim drSessionOrdersSelected As DataRow
  'Constants
  Private Const BYTES_PER_MEGABYTE As Integer = 1048576
  'Class Modules
  Dim sp As New StoredProcs
  Dim so As New SessionObjects
  
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  
      If Not (IsPostBack) Then
          'Set the current and return pages
          so.Ppage = so.Cpage
          so.Cpage = "MemberVideoDownloads.aspx"
  
          'Load the page information
          LoadPageInfo()
  
          'Rebind the GridView
          RebindGridView()
  
      End If
  
  End Sub
  
  Private Sub LoadPageInfo()
  
  End Sub
  
  Protected Sub DisplaySelectedDownloadStats()
  
  End Sub
  
  Protected Sub grvSessionOrderDownloads_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grvSessionOrderDownloads.RowCommand
  
      'Display the statistics for the orders selected for download
      DisplaySelectedDownloadStats()
  
      'Rebind the GridView
      RebindGridView()
  
  End Sub
  
  Private Sub RebindGridView()
      Dim maxDownloadsPerSession As Integer = Convert.ToInt32(ConfigurationManager.AppSettings("MaximumDownloadsPerSession"))
  
      cnnSQL = New SqlConnection(strConnection)
      If rblMemberMachine.SelectedValue = "3" Then
          cmdSQL = New SqlCommand("GetSessionOrdersForDownloadMachine3", cnnSQL)
      ElseIf rblMemberMachine.SelectedValue = "2" Then
          cmdSQL = New SqlCommand("GetSessionOrdersForDownloadMachine2", cnnSQL)
      Else
          cmdSQL = New SqlCommand("GetSessionOrdersForDownloadMachine1", cnnSQL)
      End If
      cmdSQL.CommandType = CommandType.StoredProcedure
      cmdSQL.Parameters.Clear()
      cmdSQL.Parameters.Add("@MEMB_ID", SqlDbType.VarChar, 20).Value = so.MEMB_ID
      cmdSQL.Parameters.Add("@DOWNLOAD_LIMIT", SqlDbType.Int).Value = maxDownloadsPerSession
      cnnSQL.Open()
      dadSQL = New SqlDataAdapter(cmdSQL)
      dadSQL.SelectCommand = cmdSQL
      dadSQL.Fill(dtSessionOrdersForDownload)
      cnnSQL.Close()
  
      drSessionOrdersForDownload = dtSessionOrdersForDownload.Rows(0)
      Dim Flag As Boolean = drSessionOrdersForDownload("SORD_EnableSelectionCheckBox")
  
      dvSessionOrdersForDownload = dtSessionOrdersForDownload.DefaultView
      dvSessionOrdersForDownload.Sort = "SORD_EnableSelectionCheckBox desc, SORD_Session desc, SORD_Topic, SORD_SessionTitle"
      grvSessionOrderDownloads.DataSource = dvSessionOrdersForDownload
      grvSessionOrderDownloads.DataBind()
  
  End Sub
  
  Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
  
  End Sub
  
  Protected Sub rblMemberMachine_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
      'Rebind the GridView
      RebindGridView()
  End Sub
  
  Protected Sub grvSessionOrderDownloads_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
      'Color the selected rows
  
  End Sub
  
  End Class
  </code></pre>