带有查询字符串的超链接,并在asp.net Datagrid的新窗口中打开(Hyperlink with query string and open in new window in asp.net Datagrid)

首先,我搜索了Stack OverFlow上关于我的问题的所有线程。 由于我没有找到任何预期的结果,所以我强迫自己发布这个问题。

我的问题是:我在datagrid中使用超链接并将数据字段作为查询字符串传递,我希望弹出窗口在URL中打开查询字符串,点击以下链接。

<asp:HyperLink ID="lnkViewDoc" Text='View Document' NavigateUrl='<%# string.Format("javascript:window.open('ViewDoc.aspx?DocP={0}', 'MsgWindow','width=200,height=100')", Eval("vchDocPath")) %>' runat="server"></asp:HyperLink>

在上面的代码中,我收到错误“服务器标签执行得不好。”。 谁能请我提供准确的代码?


我尝试了另一种格式。 在下面的代码中,我没有收到错误,但是当点击链接时,没有任何事情发生,就像链接不可点击一样。

<asp:HyperLink ID="lnkViewDoc" Text='View Document' NavigateUrl='Javascript:void(window.open("<%# Eval("vchDocPath", "ViewDoc.aspx?DocP={0}") %>","mywindow","toolbar=0,width=500,height=500"))' runat="server"></asp:HyperLink>

My problem is: I am using hyperlink in datagrid and passing datafield as querystring, I want pop-up window to be open with querystring in URL, when click on following link.

<asp:HyperLink ID="lnkViewDoc" Text='View Document' NavigateUrl='<%# string.Format("javascript:window.open('ViewDoc.aspx?DocP={0}', 'MsgWindow','width=200,height=100')", Eval("vchDocPath")) %>' runat="server"></asp:HyperLink>

On above code, I am getting error "The server tag is not well performed.". Can anyone please provide me exact code?


I tried another format. In following code, I am not getting error, but when clicking on link, nothing is happening like link is not clickable.

<asp:HyperLink ID="lnkViewDoc" Text='View Document' NavigateUrl='Javascript:void(window.open("<%# Eval("vchDocPath", "ViewDoc.aspx?DocP={0}") %>","mywindow","toolbar=0,width=500,height=500"))' runat="server"></asp:HyperLink>

P.S: I have tried many other formats from stack overflow and other sites, but no luck.

Thanks in advance.

最满意答案

这是一个示例html按钮,它将参数传递给javascript函数..

<head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server"> <Columns> <asp:TemplateField> <ItemTemplate> <button onclick='<%# "ShowWindow(\"" + "ViewDoc.aspx?DocP=" + Eval("vchDocPath") + "\")" %>'>View Document</button> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> </form> </body> </html> <script type="text/javascript"> function ShowWindow(e) { window.open(e, "mywindow", "toolbar=0,width=500,height=500"); } </script>

here's a sample html button that passes parameter to a javascript function..

<head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server"> <Columns> <asp:TemplateField> <ItemTemplate> <button onclick='<%# "ShowWindow(\"" + "ViewDoc.aspx?DocP=" + Eval("vchDocPath") + "\")" %>'>View Document</button> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> </form> </body> </html> <script type="text/javascript"> function ShowWindow(e) { window.open(e, "mywindow", "toolbar=0,width=500,height=500"); } </script>

更多推荐