Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 单击复选框时如何显示确认消息_C#_Asp.net - Fatal编程技术网

C# 单击复选框时如何显示确认消息

C# 单击复选框时如何显示确认消息,c#,asp.net,C#,Asp.net,我希望能够在单击asp.net复选框时显示确认消息,我尝试使用: OnClientClick = "return confirm('Are you sure you want to logout?')" 它不报告错误,但不工作,我后来发现asp.net复选框没有OnClientClick属性 我也做了一些谷歌仍然无法实现的研究!请问有人知道怎么做吗?提前谢谢。你可以看看这里 您可以使用javascript,通过选中复选框的count来实现这一点 如下 if (chkCount === 0)

我希望能够在单击asp.net
复选框时显示确认消息,我尝试使用:

OnClientClick = "return confirm('Are you sure you want to logout?')"
它不报告错误,但不工作,我后来发现asp.net复选框没有
OnClientClick
属性


我也做了一些谷歌仍然无法实现的研究!请问有人知道怎么做吗?提前谢谢。

你可以看看这里

您可以使用javascript,通过选中复选框的
count
来实现这一点

如下

 if (chkCount === 0) {
    alert("You do not have any selected files to delete.");
    return false;
} else {
    return confirm("Are you sure you want to proceed deleting the selected   files?");
}

希望对您有所帮助,因为您在下面没有提到jquery

  $(document).ready(function() {
        $('#yourelemntid_as_enderedHtml').change(function() {
            if ($(this).prop('checked')) {
                alert("Are you sure you want to logout."); //checked
            }
            else {
                alert("text here"); //not checked
            }
        });
    });
您最好在
EndprocessRequest()
上调用它,并调用此脚本

在c中#


已检查更改的受保护无效chkgen_(对象发送方,事件参数e)
{
int selRowIndex=((GridViewRow)((复选框)sender.Parent.Parent)).RowIndex;
复选框cb=(复选框)gridView.Rows[selRowIndex].FindControl(“chkgen”);
如果(cb.选中)
{
//执行你的逻辑
}
}

您可以在asp:checkbox中使用
onchange
,如下所示-

如果您设置了
autopostback=true
,它将回发

问题是,它将适用于每一个更改-无论是选中还是取消选中,为了缓解这种情况,您可以像这样使用它


经过大量研究,我能够实现这一点,以下是答案,以便其他面临同样问题的用户可以使用它:


OnClick=“if(!confirm('您确定要注销吗?'))return false;“这对我来说非常有效。

您可以将函数分配给所有复选框,然后在其中请求确认。如果选择“是”,则允许更改复选框;如果选择“否”,则复选框保持不变

在我的例子中,我还使用带有Autopostback=“True”属性的ASP.Net复选框,因此在服务器端,我需要比较提交的值和当前数据库中的值,以便知道他们选择了什么确认值,并且仅当值为“是”时才更新数据库


你能改用Javascript对话框吗?我如何在C#中调用它?该复选框不在GridView中。我如何在C#中调用它?你看到我发布的链接了吗,你需要相应地进行自定义。是的,我看到了,但我的是asp.net复选框控件,而不是html控件!您可以使用aspx控件做同样的事情,这与如何使用控件无关。
 <asp:CheckBox ID="chkgen" runat="server" Checked='<%# Eval("col3") %>'  
        OnCheckedChanged="chkgen_OnCheckedChanged"/>

protected void chkgen_OnCheckedChanged(object sender, EventArgs e)
{
      int selRowIndex = ((GridViewRow)(((CheckBox)sender).Parent.Parent)).RowIndex;
      CheckBox cb = (CheckBox)gridView.Rows[selRowIndex].FindControl("chkgen");

      if (cb.Checked)
      {
             //Perform your logic
      }
}
function Confirmation(element)
{
    if(element.checked) // so that only for checked case, this will execute.
         return confirm('Are you sure you want to logout?');
    else
         return false;
}
OnClick="if(!confirm('Are you sure you want to sign out?'))return false;"
    $(document).ready(function () {
        $('input[type=checkbox]').click(function(){                
            var areYouSure = confirm('Are you sure you want make this change?');
            if (areYouSure) {
                $(this).prop('checked', this.checked);
            } else {
                $(this).prop('checked', !this.checked);
            }
        });
    });