javascript确认对话框不能用于for循环C# [英] javascript confirm dialog not working in for loop C#

查看:87
本文介绍了javascript确认对话框不能用于for循环C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个javascript确认对话框,询问用户某个问题。我在aspx页面上有javascript代码,并在循环中从代码后面调用它,我遇到的问题是,如果用户选择多个选项在表之间传输一些数据,则确认对话框仅在传输完成后显示。



请有人告诉我哪里出错:

Hi,

I have a javascript confirm dialog that asks the user a certain question. I have the javascript code on the aspx page and calling it from code behind in a loop, the problem I am having is that if a user selects multiple options to transfer some data between tables the confirm dialog only shows up once a transfer has been made.

Please can someone tell me where I am going wrong:

foreach (ListItem Item in listbox1.Items)
{
    if (Item.Selected == true)
    {
        ScriptManager.RegisterStartupScript(this, GetType(), "progress", @"window.onload = AddMediaGroupToExisitingSuffix();", true);
        //do transfer
    }
}




function AddMediaGroupToExisitingSuffix() {
    if (confirm("'do you want to transfer data?'") == true)
        return true;
    else
        return false;
}









添加了 pre 标签。

[/编辑]

推荐答案

参考 - ScriptManager.RegisterStartupScript方法 [ ^ ]。

Refer - ScriptManager.RegisterStartupScript Method[^].
Quote:

RegisterStartupScript 方法在页面完成加载但在页面的客户端 onload 事件被引发之前执行。启动脚本块位于呈现的ASP.NET页面底部,就在< / form> 标记之前。

The script block that is rendered by the RegisterStartupScript method executes when the page finishes loading but before the page's client onload event is raised. Startup script blocks are located at the bottom of the rendered ASP.NET page just before the </form> tag.



我会建议你去 Ajax Modal Popups


这篇关于javascript确认对话框不能用于for循环C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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