如何绑定与评估和演示的OnClientClick事件javascript函数? [英] how to bind javascript function with OnClientClick event with Eval?

查看:126
本文介绍了如何绑定与评估和演示的OnClientClick事件javascript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的链接按钮 -

<asp:LinkButton runat="server" ID="lbtnEdit" Text="edit" OnClientClick="javascript:msgDisp('<%# Eval(LocationId).toString() %>')" />

和JavaScript msgDisp是 -

and the javascript msgDisp is-

<script type="text/javascript" language="javascript">
    function msgDisp(lid) {            
        alert(lid);
    }
</script>

,但它不是在弹出giiving LocationId但整个字符串&LT;%#......%>在弹出消息科曼如何通过在JavaScript评估和演示值

but it is not giiving LocationId in pop but the whole string <%#......%> is comin in popup message. How can I pass Eval values in javascript.

推荐答案

您可以建立的OnClientClick 的全部内容为code括号内的字符串,并将其会喜欢你的输出是期待的。

You can build the entire contents of OnClientClick as a string within the code brackets and it will output like you're expecting.

<asp:LinkButton runat="server" ID="lbtnEdit" Text="edit" 
    OnClientClick='<%# "msgDisp(" + Eval("LocationId") + ");" %>' /> 

这是假设LocationId是一个有效的号码 - 没有引号来包装你的价值,当它呈现,所以输出像 msgDisp(你好); 将要打破。我不知道如何解决,在这种方式下,所以如果你有这样做,我会建议设置的OnClientClick 在服务器端的的ItemDataBound 事件。下面是它想什么如果母公司是转发控制。

This is assuming LocationId is a valid number- there are no quote marks to wrap your value when it renders, so outputting something like msgDisp(hello); is going to break. I don't know how to address that in this manner, so if you have to do that I would recommend setting OnClientClick server side during the ItemDataBound event. Here's what it would like where the parent is a Repeater control.

protected void notesRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    MyClass item = (MyClass)e.Item.DataItem;
    LinkButton lbtnEdit = (LinkButton)e.Item.FindControl("lbtnEdit");
    lbtnEdit.OnClientClick = string.Format("msgDisp('{0}');", item.LocationId);
}

这篇关于如何绑定与评估和演示的OnClientClick事件javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆