RegisterClientScriptBlock - confirm box 返回一个布尔值给 aspx.cs
RegisterClientScriptBlock - confirm box return a boolean to aspx.cs
我正在尝试在执行命令之前执行确认框。我需要从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
事件将在确认窗口中单击"确定"时触发。
相关文章:
- 如何从javascript/jquery中的复选框中获取布尔值
- 将多个布尔检查简化为一个布尔检查
- KendoUI网格行过滤器,带有布尔值下拉列表
- php布尔值's小写AND大写和数字布尔值'可以接受
- 如何在javascript转换编码中将一个动态值从一个表单添加到另一个页面
- Coffeescript:添加一个由布尔值控制的条件类名
- RegisterClientScriptBlock - confirm box 返回一个布尔值给 aspx.cs
- JavaScript:为什么布尔值的按位 OR 返回一个数字而不是一个布尔值
- JavaScript后缀了一个用于限制事件的布尔值/一次性标志
- 返回一个布尔值的Angularjs自定义服务方法
- 在javascript中,是一个空字符串,作为布尔值总是为false
- 我怎么能返回一个空对象同时空对象等于布尔值false在javascript
- 存储一个布尔值或整型值,并在页面加载后检查/更改它的值
- 如何声明一个javascript变量并将其值赋给一个返回布尔值的php文件
- 这是一个很好的实践乘以一个布尔值在javascript上
- 如果没有被使用,为什么返回一个布尔值
- 为什么Angular 2's CanActivate返回一个Observable<布尔值>而不是承诺
- 调用一个为ng-show返回布尔值的函数是个好主意吗
- 如何在MongoDB中查询一个布尔值的字段,并返回一个布尔值,无论它是true还是false
- indexOf != -1返回一个布尔值吗?