【问题标题】:Show confirm dialog from code behind ASP.NET从 ASP.NET 后面的代码显示确认对话框
【发布时间】:2014-03-13 02:44:57
【问题描述】:

我想从后面的代码中显示确认对话框。

我有一个确认对话框 A。当我单击 A 上的按钮 OK 时,它在代码中调用了方法 B(使用 ajax post: url/B 和 B 是一个具有 webmethod 属性的方法)。

在方法 B 中我想显示其他对话框,并且代码正在流动:(B 是 AlertInformLogOut )

[WebMethod]
    public static void AlertInformLogOut(string alertId, string option)
    {           
            //TODO: Open call schedule
            var page = HttpContext.Current.Handler as Page;
            // PopUp alert notify info
            if (page != null)
            {
                page.ClientScript.RegisterStartupScript(page.GetType(), "script", "AlertSetDialog(" + new JavaScriptSerializer().Serialize(new AlertInformEntity()) + ", 'AlertInforms');", true);
                //ScriptManager.RegisterClientScriptBlock(page, page.GetType(), "script", "AlertSetDialog(" + new JavaScriptSerializer().Serialize(new AlertInformEntity()) + ", 'AlertInforms');", true);
            }

    }

问题是:对话框未显示。

有人能告诉我为什么吗,我可以从一个方法中显示对话框吗?有 webmethod 属性。

【问题讨论】:

  • 你如何从页面调用WebMethod
  • 我正在使用 Ajax post:$.ajax({ type: "POST", url: url+"/UpdateAlertInfo",....}

标签: c# javascript jquery asp.net


【解决方案1】:

问题是,我记得,WebMethod 不会更新页面,这与 ASP:update 面板回调不同。

当您使用 jQueries ajax 函数时,请在此处使用成功回调,而不是尝试在服务器端进行。

$.ajax({ 
   type: "POST", 
   url: url+"/UpdateAlertInfo",....,
   success: /*Call you Confirm Function Here */
 }

您也可以考虑使用$.post() 代替

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多