如何在ASP.NET c#中执行多个ClientScript.RegisterStartupScript? [英] How to execute multiple ClientScript.RegisterStartupScript in ASP.NET c#?

查看:114
本文介绍了如何在ASP.NET c#中执行多个ClientScript.RegisterStartupScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个gridview,您可以在其中单击一个按钮下载多个文件.

I'm developing a gridview in which you can download multiple files with one button.

这是我的网格视图:

<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">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

                    <Columns>
                        <asp:BoundField DataField="CorreoCliente" HeaderText="Correo Del Cliente" SortExpression="CorreoCliente" />
                        <asp:BoundField DataField="CorreosAdicionales" HeaderText="Correos Adicionales" SortExpression="CorreosAdicionales" />
                        <asp:BoundField DataField="Tema" HeaderText="Tema" SortExpression="Tema" />
                        <asp:BoundField DataField="Mensaje" HeaderText="Mensaje" SortExpression="Mensaje" />

                        <asp:TemplateField HeaderText="Fecha" SortExpression="Fecha">
                            <ItemTemplate>
                                <%# DataBinder.Eval(Container.DataItem, "Fecha", "{0:dd/MM/yyyy}")%>
                            </ItemTemplate>

                            <EditItemTemplate>
                                <asp:TextBox ID="tbxFecha" runat="server" Text='<%#Bind("Fecha","{0:dd/MM/yyyy}") %>' ValidationGroup="gpEdicionAgenda">
                                </asp:TextBox>
                            </EditItemTemplate>
                        </asp:TemplateField>

                        <asp:BoundField DataField="Hora" HeaderText="Hora" SortExpression="Hora" />
                        <asp:BoundField DataField="Archivos" HeaderText="Archivos" SortExpression="Archivos" />

                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:ImageButton ID="imgBtnDescargarArchivos" runat="server" 
                                    CommandArgument='<%# Eval("IdMensaje")%>' CommandName="Descargar" Height="16px" 
                                    ImageUrl="~/img/activar.png" ToolTip="Descargar" Width="16px" />
                            </ItemTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:ImageButton ID="imgBtnVerMas" runat="server" 
                                    CommandArgument='<%# Eval("IdMensaje")%>' CommandName="VerMas" Height="16px" 
                                    ImageUrl="~/img/search.png" ToolTip="Ver Mas" Width="16px" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>

                    <EditRowStyle BackColor="#999999" />
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <SortedAscendingCellStyle BackColor="#E9E7E2" />
                    <SortedAscendingHeaderStyle BackColor="#506C8C" />
                    <SortedDescendingCellStyle BackColor="#FFFDF8" />
                    <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                </asp:GridView>

每当我单击"Descargar" RowCommand时,我最初都使用此命令:

Whenever I click on the "Descargar" RowCommand, I originally used this:

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("<script>window.open('/Archivos/" + strArchivo + "');</script>");
                }
            }

当我单击时,如果该行有1个pdf,1个jpg和1个文档,它将在另一个窗口中打开pdf和jpg,然后将下载该文档.那正是我想要的.但是,我注意到,只要打开新页面(对于pdf和jpg),页面中的所有字体都会更改.所以我想找到一个解决方案,然后尝试了这个:

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:

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", "<script>window.open('/Archivos/" + strArchivo + "');</script>");
                }
            }

当我打开pdf文件时,这次字体没有改变,但是,它只会打开/下载出现在dt.Rows [0]中的第一个文件(打开的dt.Rows [1]不会打开) ).我想一个Response.Write可以部署多次,但是ClientScript.RegisterStartupScript可能只能执行一次.

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.

还有另一种方法可以不更改页面的字母字体,而只需单击一下即可打开多个文件吗?

Is there another method I can use to not alter the page's letter font and to open multiple files with a single click?

或者如何多次执行ClientScript.RegisterStartupScript?

Or how could I execute ClientScript.RegisterStartupScript multiple times??

预先感谢

推荐答案

一些额外的信息会有所帮助.不限于您多次使用RegisterStatupScript,但是您也可以多次注册相同的类型/键组合(这是一项功能,而非限制).

A little extra information information would be helpful. You aren't limited from using RegisterStatupScript more than once, but you are limited from registering the same type/key combination more than once (this is a feature, not a limitation).

如果需要注册其他脚本,请使用唯一键.如果您只是在做回发,则重新注册启动脚本将/应该可行.

If you need to register different scripts, use a unique key. If you are simply doing a postback, re-registering the startup script will/should work.

http://msdn.microsoft.com/zh-CN/library/system.web.ui.clientscriptmanager.aspx

这篇关于如何在ASP.NET c#中执行多个ClientScript.RegisterStartupScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆