C#中的服务器端javascript确认 [英] Server side javascript confirmation in C#

查看:84
本文介绍了C#中的服务器端javascript确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们需要调用Web服务并在确认框中显示服务返回的值,如果用户单击OK需要更新数据库,如果他点击取消需要显示原始屏幕而不执行更新逻辑。



先谢谢!!



问候,

Hari

解决方案

您可以使用这种方式。我只是给你提示,不知道你的具体情况。



Javascript:

< pre lang =Javascript>< script type = text / javascript>
function CallConfirmBox(传递值){
如果(确认( 使用 +传递值+ ?)){
// OK - Do你的东西或在这里调用任何回调方法..
alert( 你按下OK! );
return true ; // 重要
} 其他 {
// 取消 - 在这里做你的东西或调用任何回调方法..
alert( 你按下取消!);
return false ; // 重要
}
}
< / script>





.aspx加价:

 < asp:Button ID =btnCallrunat =serverText =Click Me! OnClick =btnCall_Click/> 





从代码隐藏中调用它:C#

  protected   void  btnCall_Click( object  sender,EventArgs e)
{
// service这里的代码并从此处传递您检索到的值..
string myServiceVal = 这里有一些值..;
ScriptManager.RegisterStartupScript( this this .GetType(), CallConfirmBox CallConfirmBox( ' + myServiceVal +' ); true );
// 您的剩余更新代码..
}





参考: http://www.aspneto.com/how-to-show-confirm-message-box-from-code-behind-asp-net.html [<一个href =http://www.aspneto.com/how-to-show-confirm-message-box-from-code-behind-asp-net.htmltarget =_ blanktitle =New Window> ^ ]


您需要执行以下操作:



1)调用Web服务并返回数据从服务器成功然后显示值。



.ajax({// your service parameters})。then(function(){ //显示方框})



2)之后编写代码来处理更新或不更新数据库的条件(可能需要另一个服务调用)

Hi,

We have a requirement where we need to call a web service and display the value returned from service in a confirmation box and if the user clicks OK need to update the data base and if he clicks CANCEL need to show the original screen with out executing the update logic.

Thanks in Advance !!

Regards,
Hari

解决方案

You can use this way. I'm just giving you hint, don't know your exact scenario.

Javascript:

<script type="text/javascript">
    function CallConfirmBox(passedvalue) {        
        if (confirm("Confirm Proceed Further With " + passedvalue + "?")) {
            //OK – Do your stuff or call any callback method here..
            alert("You pressed OK!");
            return true; //important
        } else {
            //CANCEL – Do your stuff or call any callback method here..
            alert("You pressed Cancel!");
            return false; //important
        }
    }
</script>



.aspx Markup:

<asp:Button ID="btnCall" runat="server" Text="Click Me!" OnClick="btnCall_Click" />



Call it from code-behind: C#

protected void btnCall_Click(object sender, EventArgs e)
{
   //service code here and pass your retrieved value from here..
   string myServiceVal = "some value here..";
   ScriptManager.RegisterStartupScript(this, this.GetType(), "CallConfirmBox",  "CallConfirmBox("'+ myServiceVal +'");", true);
   //your rest update code..
} 



Reference: http://www.aspneto.com/how-to-show-confirm-message-box-from-code-behind-asp-net.html[^]


You need to do the following:

1)Call the web service and if it returns data from the server successfully then show the value.


.ajax({//your service parameters}).then(function(){ //show the box })

2) After that write the code to handle the condition of updating or not-updating your database(which may need another service call).


这篇关于C#中的服务器端javascript确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆