单击弹出按钮确认时调用函数或在javascript中的C#中取消 [英] Call function on click of popup button ok or cancel in C# inside javascript

查看:74
本文介绍了单击弹出按钮确认时调用函数或在javascript中的C#中取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C#功能,我从DB获取值。在此基础上我必须打开一个弹出

向上显示你想继续如果按OK然后功能应该执行其他剩余代码将执行。



我尝试过:



I have C# function and I am fetching value from DB. On that basis I have to open one pop
up showing "Do you want to continue" if press OK then function should be execute else remaining code will execute.

What I have tried:

protected void lnkfreez_OnClick(object sender, EventArgs e)
        {

retSuccess = sl.FreezValue(FJ, "FreezeJmb"); // Fetching DB value
if (retSuccess == 3)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
                int Values = 0;
                sb.Append("var x=''; var r=confirm('Press a button!');");
                sb.Append("if (r==true){alert('Function Executed'); Values='" + sl.FreezValue(FJ, "funcall") + "';}");
                sb.Append("else{ alert('cancel');}");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", sb.ToString(), true);
}

//other code will excute after operation 
    SearchData(btnSearch.Text);

}





但是这个功能首先出现并且在弹出它的显示值之后......

我希望函数只有在单击OK时才会被执行。



But the fuction excuted first and after pop up its shows value..
and I want function should excuted only on click of OK.

推荐答案

您需要花时间了解asp.net页面生命周期。您的.net代码运行并生成html,然后将html发送到浏览器,但只有在执行完所有代码后才会发生。所有RegisterStartupScript都会将js注入到将要发送到浏览器的html中。它没有立即执行js,你的.net代码没有在客户端浏览器中运行。因此,您的注册行将发生,然后其余代码立即执行。如果您想询问用户是否要继续使用某些内容,则需要将其拆分为两步操作。



要求用户确认他们想继续行动| ASP.NET论坛 [ ^ ]
You need to take time to understand the asp.net page lifecycle. Your .net code runs and generates html, that html is then sent to the browser but that only happens after all of your code is executed. All RegisterStartupScript does is inject js into the html that is going to be sent to the browser. It's not executing the js right away, your .net code is not running inside the client browser. So your Register line happens then the rest of the code executes immediately. If you want to ask the user if they want to continue with something then you'll need to split it into a two-step operation.

Asking the user to confirm that they want to continue with an action | The ASP.NET Forums[^]


这篇关于单击弹出按钮确认时调用函数或在javascript中的C#中取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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