RegisterClientScriptBlock - confirm box 返回一个布尔值给 aspx.cs
本文关键字:一个 布尔值 cs aspx confirm box 返回 RegisterClientScriptBlock | 更新日期: 2023-09-27 18:36:39
我正在尝试在执行命令之前执行确认框。我需要从javascript消息框获取.cs(asp.net/c#)代码的响应。
这是我的代码
bool ReturnValue() {
return false;
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {
string commandname = e.CommandName;
if (commandname.Equals("atender")) {
ClientScriptManager CSM = Page.ClientScript;
if (!ReturnValue()) {
string strconfirm = "<script>if(!window.confirm('Are you sure?')){ I need a code here to return a false boolean to my c#}</script>";
CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);
}
// There is the code which I want to not execute if the confirmation is false
}
EDIT:
我的网格视图代码:
<asp:GridView ID="GridView1" runat="server" CellPadding="4"
BorderStyle="None" BorderWidth="0px" CellSpacing="1" Width="100%"
GridLines="Vertical" AllowPaging="True" onrowcommand="GridView1_RowCommand"
onselectedindexchanged="GridView1_SelectedIndexChanged"
onpageindexchanging="GridView1_PageIndexChanging"
onrowdatabound="GridView1_RowDataBound" PageSize="5" HorizontalAlign=Left
>
<PagerStyle HorizontalAlign="Center" />
<RowStyle CssClass="tabela_texto2" HorizontalAlign="Center"
VerticalAlign="Middle" />
<AlternatingRowStyle CssClass="tabela_texto1" />
<Columns>
<asp:ButtonField ControlStyle-CssClass="botonTransaccional" Text="Status" CommandName="atender" ButtonType="Button" />
<asp:ButtonField Text="Ver no mapa" CommandName="ver" ButtonType="Button" />
</Columns>
</asp:GridView>
这是你必须做的。首先,将ButtonField
更改为TemplateField
:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btn" runat="server" Text="Status" CommandName="atender" OnClientClick="return confirm('Are you sure?');" />
</ItemTemplate>
</asp:TemplateField>
在你背后的代码中,你不需要任何类型的逻辑。GridView1_RowCommand
事件将在确认窗口中单击"确定"时触发。