我试图在需要RowID作为参数的HyperLink上调用我的js函数,但我无法做到!
我尝试了很多方法,但总是得到null。
我怎么能做到这一点?
<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>
答案 0 :(得分:1)
使用LinkButton而不是HyperLink。见下面的例子。
<asp:LinkButton ID="btn" Text="Add voucher link" runat="server"
OnClientClick='<%# "RowClick(" + Eval("RowID") + "); return false;" %>'></asp:LinkButton>
答案 1 :(得分:0)
使用修复错误服务器标记格式不正确错误您应该使用单引号作为属性值,并在导航网址中绑定
<asp:HyperLink runat="server" NavigateUrl='<%# string.Format("javascript:RowClick({0})",Eval("RowID"))%>' Text="Add voucher link"></asp:HyperLink>
但是如果你需要简单的链接,那么更好地使用 标签,比如
<a href="javascript:RowClick('<%# Eval("RowID") %>')" >Add voucher link</a>
在我看来它简单易读