简体   繁体   中英

Adding controls to the HTMLGenericControl

I have a set of UL elements set to runat="server" in VB.NET. I am trying to load them all into a HTMLGenricControl by creating an array of them in the code behind. So that I can then just past the one HTMLGenricControl array object into my method for processing. Otherwise my method has about 18 parameters, one for each UL control. I wondered if anyone had any decent examples on how to achieve this.

Here is a couple of controls.

        <nav id="my-menu1"><ul id="ul1" runat="server"></ul></nav>        
        <nav id="my-menu2"><ul id="ul2" runat="server"></ul></nav>
        <nav id="my-menu2"><ul id="ul3" runat="server"></ul></nav>

Then in code behind Page load something like this...

    Dim objUl As HtmlGenericControl = New HtmlGenericControl("ul")
    objUl.Controls.Add(ul1)
    objUl.Controls.Add(ul2)
    objUl.Controls.Add(ul3)


    MyMethod(objUl)

Otherwise it is something like

    MyMethod(ul1, ul2, ul3)

Somehow in above code I am going slightly wrong. Was hoping someone could advise me on my lack of understanding.

add to list of Control to hold different types of controls (button, label, ..) or make it specific to HTMLGenricControl:

Dim GenericControls as new List(of Control)
GenericControls.add(ul1)

pass by reference to some method

Sub MyMethod(byref GenericControls as List(of Control)){
 For each c as Control in GenericControls
   Dim UL = Ctype(c, HtmlGenericControl )
 End for
end Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM