title: How to execute multiple ClientScript.RegisterStartupScript in ASP.NET c#?
body: <p>I'm developing a gridview in which you can download multiple files with one button.</p>
  
  <p>Here's my gridview:</p>
  
  <pre><code>&lt;asp:GridView ID="grdvHistorialMensajes" runat="server" AllowPaging="True" 
                      AutoGenerateColumns="False" CellPadding="4" AllowSorting="true"
                      EmptyDataText="No Hay Mensajes Enviados" ForeColor="#333333" 
                      GridLines="None" CellSpacing="1" 
                      onpageindexchanging="grdvHistorialMensajes_PageIndexChanging" 
                      onrowcommand="grdvHistorialMensajes_RowCommand" 
                      onsorting="grdvHistorialMensajes_Sorting"&gt;
                      &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt;
  
                      &lt;Columns&gt;
                          &lt;asp:BoundField DataField="CorreoCliente" HeaderText="Correo Del Cliente" SortExpression="CorreoCliente" /&gt;
                          &lt;asp:BoundField DataField="CorreosAdicionales" HeaderText="Correos Adicionales" SortExpression="CorreosAdicionales" /&gt;
                          &lt;asp:BoundField DataField="Tema" HeaderText="Tema" SortExpression="Tema" /&gt;
                          &lt;asp:BoundField DataField="Mensaje" HeaderText="Mensaje" SortExpression="Mensaje" /&gt;
  
                          &lt;asp:TemplateField HeaderText="Fecha" SortExpression="Fecha"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;%# DataBinder.Eval(Container.DataItem, "Fecha", "{0:dd/MM/yyyy}")%&gt;
                              &lt;/ItemTemplate&gt;
  
                              &lt;EditItemTemplate&gt;
                                  &lt;asp:TextBox ID="tbxFecha" runat="server" Text='&lt;%#Bind("Fecha","{0:dd/MM/yyyy}") %&gt;' ValidationGroup="gpEdicionAgenda"&gt;
                                  &lt;/asp:TextBox&gt;
                              &lt;/EditItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
  
                          &lt;asp:BoundField DataField="Hora" HeaderText="Hora" SortExpression="Hora" /&gt;
                          &lt;asp:BoundField DataField="Archivos" HeaderText="Archivos" SortExpression="Archivos" /&gt;
  
                          &lt;asp:TemplateField&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:ImageButton ID="imgBtnDescargarArchivos" runat="server" 
                                      CommandArgument='&lt;%# Eval("IdMensaje")%&gt;' CommandName="Descargar" Height="16px" 
                                      ImageUrl="~/img/activar.png" ToolTip="Descargar" Width="16px" /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
  
                          &lt;asp:TemplateField&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:ImageButton ID="imgBtnVerMas" runat="server" 
                                      CommandArgument='&lt;%# Eval("IdMensaje")%&gt;' CommandName="VerMas" Height="16px" 
                                      ImageUrl="~/img/search.png" ToolTip="Ver Mas" Width="16px" /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                      &lt;/Columns&gt;
  
                      &lt;EditRowStyle BackColor="#999999" /&gt;
                      &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
                      &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
                      &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt;
                      &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Center" /&gt;
                      &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt;
                      &lt;SortedAscendingCellStyle BackColor="#E9E7E2" /&gt;
                      &lt;SortedAscendingHeaderStyle BackColor="#506C8C" /&gt;
                      &lt;SortedDescendingCellStyle BackColor="#FFFDF8" /&gt;
                      &lt;SortedDescendingHeaderStyle BackColor="#6F8DAE" /&gt;
                  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Whenever I click on the "Descargar" RowCommand, I originally used this:</p>
  
  <pre><code>if (e.CommandName == "Descargar")
              {
                  DataTable dt = ConexionBD.GetInstanciaConexionBD().GetArchivosPorMensaje(Convert.ToInt32(e.CommandArgument));
  
                  foreach (DataRow dr in dt.Rows)
                  {
                      string strArchivo = dr["Nombre"].ToString();
                      string strExtension = Path.GetExtension(strArchivo).ToLower();
                      Response.Write("&lt;script&gt;window.open('/Archivos/" + strArchivo + "');&lt;/script&gt;");
                  }
              }
  </code></pre>
  
  <p>When I clicked, if that row had let's say 1 pdf, 1 jpg and 1 doc, it opened both the pdf and the jpg in a different window and the doc would be downloaded. That's exactly what I want. However, I noticed that whenever a new page is opened (in the case of the pdf and jpg) all the font in the page is altered. So I wanted to find a solution and then I tried this:</p>
  
  <pre><code>if (e.CommandName == "Descargar")
              {
                  DataTable dt = ConexionBD.GetInstanciaConexionBD().GetArchivosPorMensaje(Convert.ToInt32(e.CommandArgument));
  
                  foreach (DataRow dr in dt.Rows)
                  {
                      string strArchivo = dr["Nombre"].ToString();
                      string strExtension = Path.GetExtension(strArchivo).ToLower();
                      ClientScript.RegisterStartupScript(this.GetType(), "myFileOpenScript", "&lt;script&gt;window.open('/Archivos/" + strArchivo + "');&lt;/script&gt;");
                  }
              }
  </code></pre>
  
  <p>When I open a pdf file, the font is not altered this time, however, It would only open/download the first file that appears int dt.Rows[0] (dt.Rows[1] on won't open). I suppose that a Response.Write can be deployed multiple times, however, a ClientScript.RegisterStartupScript probably can only be executed once.</p>
  
  <p>Is there another method I can use to not alter the page's letter font and to open multiple files with a single click?</p>
  
  <p>Or how could I execute ClientScript.RegisterStartupScript multiple times??</p>
  
  <p>Thanks In Advance</p>