简体   繁体   中英

Hyperlink with query string and open in new window in asp.net Datagrid

First of all, I have searched probably all threads on Stack OverFlow about my problem. Since I haven't find any expected result, so I forced my self to post this question.

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>

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

Thanks in advance.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM