Hallo,

ich hab mal eine Frage..
Ist es möglich und wenn ja, wie kann ich eine WebUserControl dynamisch einbinden?
Ich hab ein WebUserControl mit 2 Labels (lblVorname, lblNachname).
Dieses WebUserControl möchte ich so oft in einen ContentPlaceholder einfügen, wie ich Daten von einem Webservice zu verfügen gestellt bekomme.

Meine CodeBehind-Datei der Website:


Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
        private localhost.ContactsService cs = new WebClient.localhost.ContactsService();
 
        protected void Page_Load(object sender, EventArgs e)
        {
            this.RefreshContactList();            
        }
 
 
        protected void RefreshContactList()
        {
 
            int b = cs.GetContactOverview().Count();
            string c = cs.GetContactOverview()[0].FirstName.ToString();
 
            if (cs.GetContactOverview().Count() > 0)
            {
                for (int i = 0; i <= cs.GetContactOverview().Count() - 1; i++)
                {
                    string abc = cs.GetContactOverview()[i].ContactID.ToString();
                    string def = cs.GetContactOverview()[i].GetHashCode().ToString();
                }
            }
 
            string abcd = "Test";
        }

Mein WebService:


Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
        [WebMethod(CacheDuration=10)]
        public List<Contact> GetContactOverview()
        {
 
            Contact contact = new Contact();
            List<Contact> contacts = new List<Contact>();
 
            for (int i = 0; i <= 1000; i++)
            {
                contacts.Add(contact^);
            }
            return contacts;
        }


Die Klasse 'Contact' enthält ein paar getter/setter, wie z.B. 'ContactID', 'FirstName', 'Surname', ...

Die Daten, die der Webservice zurückgibt:


Code :
1
2
3
4
5
6
7
8
9
10
11
12
<ArrayOfContact>
<Contact>
<ContactID>1</ContactID>
<FirstName>Timur</FirstName>
<Surname>C</Surname>
</Contact>
<Contact>
<ContactID>1</ContactID>
<FirstName>Timur</FirstName>
<Surname>C</Surname>
</Contact>
</ArrayOfContact>



Mein ContentPlaceholder:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContactObject.ascx.cs" Inherits="WebClient.Controls.ContactObject" %>
    <asp:Panel ID="pnlContactObject" CssClass="pnlcontactobject" runat="server">       <table style="width: 100%; border: 0px;" id="htblmailobject">
            <tr>
                <td style="width:20px;">
                    <img src="../Images/contact_icon.png" style="width: 18px; height: 15px" />&nbsp;&nbsp;
                </td>
                <td>
                    <asp:Label ID="lblSurname" runat="server" Text=""></asp:Label>,&nbsp;
                    <asp:Label ID="lblFirstname" runat="server" Text=""></asp:Label>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
        </table>
    </asp:Panel>

Vielen Dank im Vorraus.

Gruß
Timur