Nat*_*nar 2 javascript c# asp.net
我在 OnClientClick 中使用数据绑定 Eval 时遇到问题,我找不到正确进行此绑定的方法。这是我的代码
<asp:LinkButton runat="server" ID="ItemMenuBtn" CssClass="ui-button ui-widget ui-corner-all" OnClientClick='OpenItemMenu(<%# Eval("NotificationData") %>);return false;'>
<i class="fa fa-lg fa-bars" aria-hidden="true"></i>
</asp:LinkButton>
Run Code Online (Sandbox Code Playgroud)
我希望输出类似于:
<a onclick="OpenItemMenu({JSON notification data here});return false;" id="some id" class="ui-button ui-widget ui-corner-all">
Run Code Online (Sandbox Code Playgroud)
但相反,我得到:
<a onclick="OpenItemMenu(<%# Eval("NotificationData") %>);return false;" id="ctl00_m_g_28e3d385_2509_4d3a_9c53_1d17b87a802b_gvNoteworthyItems_ctl02_ItemMenuBtn" class="ui-button ui-widget ui-corner-all" href="javascript:__doPostBack('ctl00$m$g_28e3d385_2509_4d3a_9c53_1d17b87a802b$gvNoteworthyItems$ctl02$ItemMenuBtn','')">
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:
对于OnClientClick,您可以尝试:
OnClientClick='<%# string.Format("OpenItemMenu(\"{0}\"); return false", Eval("NotificationData")) %>'
Run Code Online (Sandbox Code Playgroud)
如果 LinkButton 不在数据绑定控件中,则必须调用DataBind以确保计算数据绑定表达式:
protected void Page_Load(object sender, EventArgs e)
{
ItemMenuBtn.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
默认情况下,单击 LinkButton 会在__doPostBack. false在OnClientClick事件处理程序中返回会取消回发。
| 归档时间: |
|
| 查看次数: |
3823 次 |
| 最近记录: |