Adding 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
- In Design view, drag an XML control from the Web Forms tab of the Toolbox onto the page.
- 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 Loading XML Data in the XML Web Server Control.
Note You need to be sure that when your application runs, it has sufficient permissions to read the XML file. For details, see Access Permissions for Web Applications.
To add a control to a Web Forms page programmatically
- Create an instance of the control and set its properties:
' Visual Basic Dim myXML As System.Web.UI.WebControls.Xml = _ New System.Web.UI.WebControls.Xml() myXML.DocumentSource = "SourceDoc.xml" myXML.TransformSource = "SourceTrans.xsl" // C# System.Web.UI.WebControls.Xml myXML = new System.Web.UI.WebControls.Xml(); myXML.DocumentSource = "SourceDoc.xml"; myXML.TransformSource = "SourceTrans.xsl";
- Add the new control to the Controls collection of a container already on the page:
' Visual Basic PlaceHolder1.Controls.Add(myXML) // C# 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 Introduction to Web Forms State Management.