다음을 통해 공유


How to: Add XML Web Server Controls to a Web Forms Page

Add Xml Web server controls to the place in the page where you want the output to appear.

To add an XML Web server control to a Web Forms page

  1. From the Standard tab of the Toolbox, drag an Xml control onto the page.

  2. Load the XML data that you want to display into the control by setting the Document or DocumentSource property, or by putting the XML between the control's opening and closing tags. For details, see How to: Load XML Data in the XML Web Server Control.

    Note

    Make sure that when your application runs, it has the appropriate permissions to read the XML file. For details, see ASP.NET Authorization.

To add an XML Web server control to a Web Forms page programmatically

  1. Create an instance of the Xml control and set its properties, as shown in the following code example:

    Dim myXML As System.Web.UI.WebControls.Xml = _
        New System.Web.UI.WebControls.Xml()
    myXML.DocumentSource = "SourceDoc.xml"
    myXML.TransformSource = "SourceTrans.xsl"
    
    System.Web.UI.WebControls.Xml myXML = 
        new System.Web.UI.WebControls.Xml();
    myXML.DocumentSource = "SourceDoc.xml";
    myXML.TransformSource = "SourceTrans.xsl";
    
  2. Add the new control to the Controls collection of a container that is already on the page, as shown in the following code example:

    PlaceHolder1.Controls.Add(myXML)
    
    PlaceHolder1.Controls.Add(myXML);
    

    Note

    Controls that you add dynamically to a Web Forms page do not automatically become part of the page's view state — neither the controls nor their values are saved when a page performs a round trip to the server. You are therefore responsible for saving the state of any dynamically-generated controls whose values you want to preserve. For details, see ASP.NET State Management Overview.

See Also

Reference

XML Web Server Control Overview