Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 是否仍要从contentpage更新面板修改母版页控件?_Asp.net_Ajax_Master Pages - Fatal编程技术网

Asp.net 是否仍要从contentpage更新面板修改母版页控件?

Asp.net 是否仍要从contentpage更新面板修改母版页控件?,asp.net,ajax,master-pages,Asp.net,Ajax,Master Pages,下面是我为一个web应用程序的单一源弹出模式提出的建议。 我在母版页上放了一个占位符,下面的代码放在一个单独的类中。类文件接收消息并构建模式html 这适用于完全回发,但在ajax更新面板中调用时不起作用 Public Shared Sub showModalMsg(ByVal sMsg As String, Optional ByVal container As Control = Nothing) 我知道为什么。我只是不知道有什么

下面是我为一个web应用程序的单一源弹出模式提出的建议。 我在母版页上放了一个占位符,下面的代码放在一个单独的类中。类文件接收消息并构建模式html

这适用于完全回发,但在ajax更新面板中调用时不起作用

Public Shared Sub showModalMsg(ByVal sMsg As String,
                              Optional ByVal container As Control = Nothing)
我知道为什么。我只是不知道有什么办法可以绕过它。有什么想法吗

 Public Class Common
  Inherits SiteMaster    

  Public Shared Sub showModalMsg(ByVal sMsg As String)

    Dim lbl As New Label
    lbl.Text = sMsg
    '(for simplicity, the building of the div to make the modal is omitted)


    Dim pageHandler = HttpContext.Current.CurrentHandler
    If TypeOf pageHandler Is System.Web.UI.Page Then
        Dim ph As PlaceHolder = DirectCast(pageHandler, System.Web.UI.Page).Master.FindControl("phModalDialog")
        If ph IsNot Nothing Then
            ph.Controls.Add(lbl)
        End If
    End If

 End Class

好的,这就是我所做的。我添加了一个名为“container”的可选变量,在更新面板中调用对话框时可以传递该变量

Public Shared Sub showModalMsg(ByVal sMsg As String,
                              Optional ByVal container As Control = Nothing)
我在这里发布了我的完整解决方案: