Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.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
Javascript 如何从服务器端调用确认对话框_Javascript_C#_Asp.net - Fatal编程技术网

Javascript 如何从服务器端调用确认对话框

Javascript 如何从服务器端调用确认对话框,javascript,c#,asp.net,Javascript,C#,Asp.net,我的页面中有一个按钮,如果条件匹配,单击事件将执行特定代码,否则它将要求确认是否继续。我有一个用于确认的javascript函数,如下所示 <script type="text/javascript"> function getConfirmation(){ var retVal = confirm("Do you want to continue ?"); if( retVal == true )

我的页面中有一个按钮,如果条件匹配,单击事件将执行特定代码,否则它将要求确认是否继续。我有一个用于确认的javascript函数,如下所示

<script type="text/javascript">

            function getConfirmation(){
               var retVal = confirm("Do you want to continue ?");
               if( retVal == true ){

                  return true;
               }
               else{

                  return false;
               }
            }

      </script>
<asp:Button runat="server" ID="lnkBtn" onClick="lnkBtn_Click" onClientClick="getConfirmation()"></button>
现在的问题是,即使在不满足条件的情况下,单击按钮也会触发confirm()。我希望confirm()仅在满足条件时才会触发。请帮我做这个

提前感谢你

我尝试了两种解决方案,但似乎我在某个地方犯了错误。我附上下面的完整代码。请你帮我找出我错在哪里,以及如何纠正

<script type="text/javascript">
        function Confirm() {
            var confirm_value = document.createElement("INPUT");
            confirm_value.type = "hidden";
            confirm_value.name = "confirm_value";
            if (confirm("This will completely delete the project. Are you sure?")) {
                confirm_value.value = "Yes";
            }
            else {
                confirm_value.value = "No";
            }
            document.forms[0].appendChild(confirm_value);
        }
    </script>

<asp:Button runat="server" ID="lnkBtn" onClick="lnkBtn_Click" onClientClick="getConfirmation()"></button>

使用txtID.Text单击ibExport时=“”中,不显示确认对话框。相反,“未单击”警报会直接弹出。

如果非常接近,请在内联单击处理程序中使用
return
语句

onClientClick="return getConfirmation()"
而不是

onClientClick="getConfirmation()"
此外,
getConfirmation
函数中的
if
块是冗余的

function getConfirmation() {
    return confirm("Do you want to continue ?");
}

非常接近,请在内联单击处理程序中使用
return
语句

onClientClick="return getConfirmation()"
而不是

onClientClick="getConfirmation()"
此外,
getConfirmation
函数中的
if
块是冗余的

function getConfirmation() {
    return confirm("Do you want to continue ?");
}

删除Javascript。并在后端为按钮单击事件使用此函数

void lnkBtn_Click(Object sender, EventArgs e)
    {
        if (txtMyText.Text!="")
        {
             Response.Write("<script> function getConfirmation()"
            +" { var retVal = confirm('Do you want to continue ?');"
            +" if( retVal == true )"
            +" { return true; } else{ return false;} }"
            +" </script>");
        }
        else
        {
        //continue with normal code.    
        }
    }   
void lnkBtn\u单击(对象发送方,事件参数e)
{
if(txtMyText.Text!=“”)
{
Write(“函数getConfirmation()”
+“{var retVal=confirm('是否继续?')
+“如果(retVal==true)”
+“{return true;}否则{return false;}}”
+" ");
}
其他的
{
//继续正常代码。
}
}   

删除您的Javascript。并在后端为按钮单击事件使用此函数

void lnkBtn_Click(Object sender, EventArgs e)
    {
        if (txtMyText.Text!="")
        {
             Response.Write("<script> function getConfirmation()"
            +" { var retVal = confirm('Do you want to continue ?');"
            +" if( retVal == true )"
            +" { return true; } else{ return false;} }"
            +" </script>");
        }
        else
        {
        //continue with normal code.    
        }
    }   
void lnkBtn\u单击(对象发送方,事件参数e)
{
if(txtMyText.Text!=“”)
{
Write(“函数getConfirmation()”
+“{var retVal=confirm('是否继续?')
+“如果(retVal==true)”
+“{return true;}否则{return false;}}”
+" ");
}
其他的
{
//继续正常代码。
}
}