Reputation: 261
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>
Upvotes: 0
Views: 603
Reputation: 13381
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
Upvotes: 0
Reputation: 169
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>
Upvotes: 1