[英]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! 我试图在需要RowID作为参数的HyperLink上调用我的js函数,但我做不到!
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. 使用LinkButton而不是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 我认为它简单易读
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.