C# 确认对话框以及如何在代码隐藏中控制它
当我加载页面时,我加载此脚本:C# 确认对话框以及如何在代码隐藏中控制它,c#,javascript,asp.net,code-behind,scriptmanager,C#,Javascript,Asp.net,Code Behind,Scriptmanager,当我加载页面时,我加载此脚本: ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "question", "<script type = 'text/javascript'>if(confirm('Are you sure you want to do this?')) retur
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);
ScriptManager.RegisterStartupScript(this.Page,this.Page.GetType(),
“问题”,
“如果(确认('您确定要执行此操作吗?'))返回true;否则返回false;”,
假);
我不知道当用户单击是在代码隐藏中执行某项操作时,以及当单击否执行其他操作时,该如何处理?如何在代码隐藏中处理此单击?如果返回真/假,则在代码隐藏中只能得到真。 要获取false的值,还必须创建另一个函数
我喜欢的最佳方法是在hiddenfield中设置返回参数的值。在codebehind中获取此变量并相应地工作。您已经有了相应的代码。 您只能在Yes或NO上调用javascript函数,但javascript函数可以使用Ajax调用codebehind webmethods。
ScriptManager.RegisterStartupScript(this.Page,this.Page.GetType(),
“问题”,
“如果(确认('您确定要执行此操作吗?'){[Call Function for Yes]}其他{[Call Function for No或Cancel];}”,
假);
除了WebMethods技术,您还可以选择使用\uuuDoPostback方法从javascript代码中找到隐藏的代码。有关其用法的详细信息,请访问
使用WebMethods的一个限制是,由于它们始终是静态的,因此无法访问它们内部的非静态字段、方法和控件
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);