Search code examples
asp.net.netvb.netascx

How can I send an XML string to an ASCX Repeater Control?


I'm writing a Repeater Control in an ascx file which renders some info as a row that comes from a complex search. In an aspx file I have the query to retrieve a DataView that gives me the XML string with the info needed to feed the Repeater. The problem is that I don't know how can I pass the XML string (or the DataView or DataSet) from the aspx to the ascx file so as I can render the info.

Thank you.


Solution

  • You need to expose a property or a method on the User Control so that the page referencing the ASCX control can receive the XML and do something with it (bind it to your repeater).

    You can perfectly create a method inside your ASCX control like this:

    public void BindXml(string xml)
    {
    
        //bind the xml to the repeater
    }
    

    As a property...

    public string XMLData { set 
                            { 
                              //use a DataSet to load the xml passed and bind it to 
                              //the repeater
                              DataSet dataset = new DataSet();
                              dataset.ReadXml(value);
                              repeater.DataSource=dataset; repeater.DataBind(); 
                              }
                            }
    

    The aspx page can call the method like so:

    yourusercontrol.BindXML(xml);
    

    Or the property:

    yourusercontrol.XMLData=xml;