我在MyClass类中创建了一个函数。此功能旨在包含样式表和js代码:
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到目前为止,一切都正常,实际上在源代码中包含了JavaScript代码。我的问题是:如何确保Myfunction ()包含多个样式表/javascript代码?
这种方式不起作用:
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谢谢
发布于 2016-09-28 22:33:32
通常,您可以在其他HtmlGenericControl.中嵌套HtmlGenericControl
如果您计划在页面底部呈现这些JavaScripts,可以将其放在div标记中。
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 Functiondiv仅供参考:如果您计划在标题标记内部呈现,则不希望将它们放在中。然后,您必须调用该方法两次。
https://stackoverflow.com/questions/39748589
复制相似问题