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[^].
由 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
。