0

I'm using this bit of code to add a CSS link in the head section :

<script runat="server">
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
Dim oCSS As Control = Me.Page.FindControl("CSS")
If Not oCSS is Nothing Then
Dim oLink As New HtmlGenericControl("link")
oLink.Attributes("id") = "MyCss"
oLink.Attributes("rel") = "stylesheet"
oLink.Attributes("type") = "text/css"
oLink.Attributes("href") = SkinPath & "MyCss.css"
oCSS.Controls.AddAt(0, oLink)
End if
End Sub
</script>

It works, but the problem is that this places the CSS link on top of all other links in the HEAD section. Is there a way to make this link appear at the bottom of all other CSS links ?

Better still, can it be placed after a particular CSS link already in the head section ?

Also, how does they Controls.AddAt(0, oLink) work. It does not accept any other number other than "0" for the index.

Thank you in advance, :).

1 Answer 1

1

From your code I suspect the Controls is a ControlsCollection and the documentation for the AddAt method tells you that the first argument is the place in the collection (0 = first) where the control is to be added.

try this instead

oCSS.Controls.Add(oLink)

or

oCSS.Controls.AddAt(oCSS.Controls.Count, oLink)

Edit:

Try finding the right control with the Me.Page.FindControl("NameOfControl")

Sign up to request clarification or add additional context in comments.

1 Comment

Both these options still add the link at the top of the first CSS link Tag. ... Is there a way to add this at the top of any other tag ... say just before the 'Title' tag. ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.