繁体   English   中英

在OnClick之前如何执行OnClientClick?

[英]How to perform OnClientClick before OnClick?

我在listView内有带有OnClick事件和OnClientClick按钮。 onClientClick具有JS功能确认('sure ??')。 确认消息应在特定条件下回发之前出现。 如何根据listview 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;" />

不确定是否可行,但是如何将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;";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM