简体   繁体   中英

Return multiple HtmlGenericControl

I created a function in a class MyClass. This feature is intended to include stylesheets and js code:

Public Function myfunction() As HtmlGenericControl
        Dim bootstrapmin As New HtmlGenericControl("script")
        bootstrapmin.Attributes("href") = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js" 
        Return bootstrapmin
End Function

So far everything is working, actually in the source code is included JavaScript code. My problem is: How can I make sure that Myfunction () includes multiple stylesheets/javascript code?

This way does not work:

Public Function test3() As HtmlGenericControl
         Dim bootstrapmin As New HtmlGenericControl("script")
            bootstrapmin.Attributes("src") = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js" 
            Return bootstrapmin

     Dim bootstrap As New HtmlGenericControl("script")
            bootstrap.Attributes("src") = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.js"
            Return bootstrap
        End Function

THANK YOU

Normally, you can nest HtmlGenericControl inside other HtmlGenericControl .

If you plan to render those JavaScripts at the bottom of a page, you can place it inside div tag.

Public Function test3() As HtmlGenericControl
    Dim div = New HtmlGenericControl("div")

    Dim bootstrapmin = New HtmlGenericControl("script")
    bootstrapmin.Attributes("src") = 
       "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"
    div.Controls.Add(bootstrapmin)

    Dim bootstrap = New HtmlGenericControl("script")
    bootstrap.Attributes("src") = 
       "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.js"
    div.Controls.Add(bootstrapmin)

    Return div
End Function

FYI: If you plan to render inside header tag, you do not want to place them inside div. Then you will have to call that method twice.

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