簡體   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