如何在回发期间持久保存XMLDocument?

时间:2011-12-27 16:54:47

标签: vb.net postback xmldocument persist

如何在回发后保留XML文档?

我将此xmlDocument保存在SaveViewState()方法中:

    Private _xmlSaveDispatch As XmlDocument = New XmlDocument

在我的Page_Load ...

If Not IsPostBack Then 
   Me._xmlSaveDispatch = New XmlDocument 

Private Property XMLSaveDispatch As XmlDocument 
  Get 
    Return _xmlSaveDispatch 
  End Get 

  Set(value As XmlDocument) 
      _xmlSaveDispatch = value 
  End Set 
End Property 

Button Click Event: 
Protected Sub dispatchButton_OnSave(sender As Object, e As EventArgs) _ 
     Handles dispatchButtons.SaveDispatch 
   XMLSaveDispatch = _objDispatchInfo.GetSaveXML() 
End Sub 

1 个答案:

答案 0 :(得分:0)

我正在编写一个C#应用程序并遇到了同样的问题(asp:Xml标记在回发之间不会持续存在)。这是我在C#中保留它的代码:

//.aspx Presentation
<asp:Xml ID="xmlFormDisplay" runat="server"></asp:Xml>

//.aspx.cs Code Behind
private string formXSLT
{
    get { return ViewState["FormXSLT"].ToString(); }
    set { ViewState["FormXSLT"] = value; }
}
private string formXML
{
    get { return ViewState["FormXML"].ToString(); }
    set { ViewState["FormXML"] = value; }
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
         ...
    }

    xmlFormDisplay.TransformSource = formXSLT;
    xmlFormDisplay.DocumentContent = formXML;
}

我不是一个VB开发人员,但这应该工作(或非常接近):

//.aspx Presentation
<asp:Xml ID="xmlFormDisplay" runat="server"></asp:Xml>

//.aspx.vb Code Behind
Private Property FormXSLT As String
    Get 
        Return ViewState["FormXSLT"].ToString() 
    End Get 
    Set(value As String) 
        ViewState["FormXSLT"] = value 
    End Set 
End Property

Private Property FormXML As String
    Get 
        Return ViewState["FormXML"].ToString() 
    End Get 
    Set(value As String) 
        ViewState["FormXML"] = value 
    End Set 
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then 
         ...
    End If

    xmlFormDisplay.TransformSource = formXSLT
    xmlFormDisplay.DocumentContent = formXML
End Sub