简体   繁体   中英

Js function call with param on HyperLink

I am trying to call my js function on a HyperLink that needs RowID as a parameter and I cant do it!

I have try a lot of ways but always i get null.

How I can achieve this?

<script>
        var popUpObj;

        function RowClick(filterId) {

            popUpObj = window.open("voucher.aspx?param=" + filterId + "",
             "ModalPopUp",
             "toolbar=no," +
             "scrollbars=no," +
             "location=no," +
             "statusbar=no," +
             "menubar=no," +
             "resizable=0," +
             "width=530," +
             "height=500," +
             "left = 450," +
             "top=130"
            );
             popUpObj.focus();
             LoadModalDiv();


         }
    </script>



 <MasterTableView ClientDataKeyNames="RowID" AllowPaging="True" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" CommandItemDisplay="Top" DataKeyNames="RowID" AllowCustomPaging="False" AutoGenerateColumns="False" AllowMultiColumnSorting="True"   >
            <Columns>
                <telerik:GridBoundColumn DataField="RowID" DataType="System.Int32" FilterControlAltText="Filter RowID column" HeaderText="RowID" ReadOnly="True" SortExpression="RowID" UniqueName="RowID" Visible="False">
                </telerik:GridBoundColumn>

     <telerik:GridTemplateColumn FilterControlAltText="Filter RowID column" UniqueName="RowID" >
                        <ItemTemplate>
                            <asp:HyperLink runat="server" NavigateUrl="javascript:RowClick()"  Text="Add voucher link"></asp:HyperLink>

                             </ItemTemplate>
                    </telerik:GridTemplateColumn>

Use LinkButton instead of HyperLink. See example below.

<asp:LinkButton ID="btn" Text="Add voucher link" runat="server" 
 OnClientClick='<%# "RowClick(" + Eval("RowID") + "); return false;" %>'></asp:LinkButton>

For fix your error with The server tag is not well formed error you should use single quotes for attribute values, and make navigate url inside binding

<asp:HyperLink runat="server" NavigateUrl='<%# string.Format("javascript:RowClick({0})",Eval("RowID"))%>'  Text="Add voucher link"></asp:HyperLink>

But in case when you need simple link, methinks better use just a tag, something like

<a href="javascript:RowClick('<%# Eval("RowID") %>')" >Add voucher link</a>

in my opinion it easy and more readable

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