【问题标题】:How to perform OnClientClick before OnClick?如何在 OnClick 之前执行 OnClientClick?
【发布时间】:2014-04-20 11:15:45
【问题描述】:

我在listView 内部有带有OnClick 事件和OnClientClick 的按钮。 onClientClick 有 JS 函数 confirm('sure??')。确认消息应在特定条件下在回发之前出现。如何根据列表视图itemDataBound()中的条件执行onClientClick

代码:

protected void lvCo_ItemDataBound(object sender, ListViewItemEventArgs e){
int Req = Convert.ToInt32(((Label)e.Item.FindControl("lblCoId")).Text);

if (Req==5)
   // Show Confirmation Message 
else
   // Don't Show the Confirmation Message
}

aspx:

<asp:ListView ID="lvCo" runat="server" DataKeyNames="CoId"                    OnItemCommand="lvCoFind_ItemCommand" OnItemDataBound="lvCo_ItemDataBound">
   // .. Layouttemplate .. && Itemtemplate

    <asp:Button Text="Save" ID="btSaveOp" CommandName="Save"  runat="server" OnClientClick="if (!confirm('Are you sure?')) return false;" />

【问题讨论】:

  • 条件是什么?
  • 密码是什么?我不明白你在这方面有什么问题。
  • 对不起,弱点问题,我复制代码

标签: c# jquery asp.net


【解决方案1】:

不确定这是否可行,但是如何将 onclientclick 移出 aspx 页面并在后面的代码中进行设置。

protected void lvCo_ItemDataBound(object sender, ListViewItemEventArgs e){
int Req = Convert.ToInt32(((Label)e.Item.FindControl("lblCoId")).Text);

if (Req==5) // Show Confirmation Message 
   ((Button)e.Item.FindControl("btSaveOp")).OnClientClick = "if (!confirm('Are you sure?')) return false;";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-03
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 1970-01-01
    相关资源
    最近更新 更多