Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.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语言的代码隐藏中跟踪警报的确认取消事件#_C#_Javascript_Asp.net_Alert - Fatal编程技术网

C# 如何在C语言的代码隐藏中跟踪警报的确认取消事件#

C# 如何在C语言的代码隐藏中跟踪警报的确认取消事件#,c#,javascript,asp.net,alert,C#,Javascript,Asp.net,Alert,我的要求很简单,但似乎很复杂 我正在使用C代码和java脚本 我想使用带有确认/取消按钮的警报消息,我想从代码后面跟踪用户的单击,比如说他是否按下了警报消息的确认按钮,或者说他是否单击了警报消息的取消按钮 比如说,从c#代码隐藏页面我调用了confirmDuplicateCustomerCreation function confirmDuplicateCustomerCreation() { confirm('Customer with same details already

我的要求很简单,但似乎很复杂

我正在使用C代码和java脚本

我想使用带有确认/取消按钮的警报消息,我想从代码后面跟踪用户的单击,比如说他是否按下了警报消息的确认按钮,或者说他是否单击了警报消息的取消按钮

比如说,从c#代码隐藏页面我调用了confirmDuplicateCustomerCreation

function confirmDuplicateCustomerCreation() {
        confirm('Customer with same details already exists. Do you want to continue?')
}


protected void Button1_Click(object sender, EventArgs e) 
{ ScriptManager.RegisterStartupScript(
    this,
    this.GetType(), 
    Guid.NewGuid().ToString(),
    @"<script type='text/javascript'>confirmDuplicateCustomerCreation();</script>", 
    false); 
    Label1.Text = Convert.ToString(CustomerDuplicateFlag.Value); 
} 

<script type="text/javascript"> 
  function confirmDuplicateCustomerCreation() { 
      if(confirm('Customer with same details already exists. Do you want to continue?'))  
          document.getElementById('<%=CustomerDuplicateFlag.ClientID %>').value = 'Yes'; 
      else 
          document.getElementById('<%=CustomerDuplicateFlag.ClientID %>').value = 'No'; } 
</script> 
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> 
<asp:HiddenField ID="CustomerDuplicateFlag" runat="server />
函数confirmDuplicateCustomerCreation(){
确认('已存在具有相同详细信息的客户。是否继续?')
}
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{ScriptManager.RegisterStartupScript(
这
this.GetType(),
Guid.NewGuid().ToString(),
@“confirmDuplicateCustomerCreation();”,
假);
Label1.Text=Convert.ToString(CustomerDuplicateFlag.Value);
} 
函数confirmDuplicateCustomerCreation(){
if(确认('已存在具有相同详细信息的客户。是否要继续?'))
document.getElementById(“”).value='Yes';
其他的
document.getElementById(“”).value='No';}

您可以将确认值保存在隐藏字段中,然后自己将页面回发到服务器

ASPX
你好,雷内,谢谢你的建议。但我需要通过警报消息来实现这一点,你有没有想法通过警报框消息来实现这一点?我只是想知道,警报消息事件确认或取消是否可以在代码背后跟踪?在这种情况下,你需要获取调用
yesno=confirm(“blah”)返回的布尔值
,使用javascript/jquery在表单上找到一个隐藏的复选框,将值放入其中并提交表单……这个答案很有用:问题是,当您通过javascript在变量中赋值时,在回发之前,我们无法访问变量的值。但我需要一次性访问该值,我的意思是在检查时调用javascript ad assigng变量value,然后在代码后面访问值。但是在回发之前,在代码隐藏中无法访问该值。在下一篇文章中,我将获取分配的值,该值是由hrouh javascript创建您自己的自定义警报完成的?
<asp:Button runat="server" ID="Button1"
    Text="Submit"
    OnClick="Button1_Click" />

<asp:HiddenField runat="server" ID="HiddenField1"
    OnValueChanged="HiddenField1_ValueChanged" />

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
    function confirmDuplicateCustomerCreation() {
        var value = confirm('Customer with same details already exists. Do you want to continue?');
        $('#<%= HiddenField1.ClientID %>').val(value);
        // By default, OnValueChanged of HiddenField doesn't auto post back to server, 
        // so we need to trigger the post back here by ourself.
        __doPostBack('', '');
    }
</script>
protected void Button1_Click(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(
        this,
        this.GetType(),
        UniqueID,
        "confirmDuplicateCustomerCreation();",
        true);
}

protected void HiddenField1_ValueChanged(object sender, EventArgs e)
{
    if (Convert.ToBoolean(HiddenField1.Value))
    {
        // User clicked OK at Confirmation   
    }
}