[英]Js function call with param on HyperLink
我試圖在需要RowID作為參數的HyperLink上調用我的js函數,但我做不到!
我嘗試了很多方法,但總會得到空值。
我該如何實現?
<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>
使用LinkButton而不是HyperLink。 請參見下面的示例。
<asp:LinkButton ID="btn" Text="Add voucher link" runat="server"
OnClientClick='<%# "RowClick(" + Eval("RowID") + "); return false;" %>'></asp:LinkButton>
要修復服務器標簽格式錯誤的錯誤 ,應為屬性值使用單引號,並在綁定內設置導航網址
<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>
我認為它簡單易讀
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.