【问题标题】:Updating the master page when the control is within an update panel on the content page. i am trying lot but not get success?当控件位于内容页面上的更新面板中时更新母版页。我正在尝试很多但没有成功?
【发布时间】:2013-12-09 08:24:06
【问题描述】:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

    Master.settxtvalue.Text = Me.TextBox1.Text
    Me.Button1 = TryCast(Me.Master.FindControl("mdlpp").FindControl("Button1"), Button)

End Sub


Public ReadOnly Property settxtvalue() As TextBox
    Get
        Return Me.TextBox18
    End Get
End Property

【问题讨论】:

    标签: asp.net updatepanel ajaxcontroltoolkit master-pages


    【解决方案1】:

    您不能直接这样做,您必须使用 ScriptManager.RegisterStartupScript() 函数,该函数将注入 java 脚本语句,该语句将在更新面板获取更新时执行。并添加 java 脚本语句来查找要更新的元素并设置它的值。

    像下面的c#代码一样将其转换为VB并使用

    string strUpdate = "document.getElementById('" + Master.settxtvalue.ClientID + "').value = '" + Me.TextBox1.Text + "'";
    ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "msupdate", strUpdate, true);
    

    这里的 UpdatePanel1 是你更新面板的 id。替换以下代码行

    Master.settxtvalue.Text = Me.TextBox1.Text
    

    有了它。

    这是VB版

    Dim strUpdate As String = ("document.getElementById('" + Master.settxtvalue.ClientID & "').value = '") + [Me].TextBox1.Text & "'"
    ScriptManager.RegisterStartupScript(UpdatePanel1, Me.[GetType](), "msupdate", strUpdate, True)
    

    【讨论】:

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