确认对话框和如何控制它的代码后面

Confirm dialog and how to control it in code behind

本文关键字:代码 控制 对话框 何控制 确认      更新时间:2023-09-26

当我加载页面时,我加载了这个脚本:

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
                              "question",
                              "<script type = 'text/javascript'>if(confirm('Are you sure you want to do this?')) return true; else return false;</script>",
                              false);

我不知道如何处理当用户点击在代码后面做一些事情,当点击没有做一些其他的事情?
如何处理这个点击在代码后面?

如果您返回true/false,那么在后面的代码中您将只得到true。要获取false的值,还必须创建另一个函数。

我喜欢的最好的方法是在hiddenfield中设置返回参数的值。在代码后面获取这个变量并相应地工作

您已经有了相应的代码。你只能在Yes或NO上调用javascript函数。但是Javascript函数可以使用Ajax调用代码后的web方法。

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
                              "question",
                              "<script type = 'text/javascript'>if(confirm('Are you sure you want to do this?')){[Call Function for Yes]} else{ [Call Function for No or Cancel];}</script>",
                              false);

除了WebMethods技术,您还可以选择使用__doPostBack方法从javascript代码中命中代码延迟。有关其使用的更多信息,请访问http://aspalliance.com/895_Understanding_the_JavaScript___doPostBack_Function.all, http://dopostback.net/。

使用WebMethods的一个限制是,因为它们总是静态的,你的非静态字段、方法和控件将无法在其中访问。http://forums.asp.net/t/1531113.aspx/1。