0

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>
9
  • you call "javascript:RowClick()" without params, so sure you have filterId param undefined. How you try pass parameter? Commented May 26, 2015 at 8:19
  • Yes with javascript:RowClick(RowID) and still null Commented May 26, 2015 at 8:21
  • where you get RowID? Commented May 26, 2015 at 8:22
  • ClientDataKeyNames="RowID" Commented May 26, 2015 at 8:22
  • so you just write NavigateUrl="javascript:RowClick(RowID)"? NavigateUrl is just string, and it rendered as is, so in html you have something like <a href="javascript:RowClick(RowID)"> and sure it not work Commented May 26, 2015 at 8:23

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Uncaught SyntaxError: Unexpected token <
Edited the LinkButtoncontrol. Use the example as a guide.
still : Uncaught ReferenceError: filterId is not defined
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.