asp.net - Register stylesheet from web control on page with UpdatePanel -
What is the best way to register a stylesheet once on the page with a customer web control? Please keep in mind that the page uses an UpdatePanel for async calls. I just tried putting The script is registered for the type 'myControl' type and invalid in the key 'Mikey' outside the script tag Characters are: Only properly formatted script tags can be registered. If I try to add to the page by adding it to the control hierarchy, it appears once for each instance of your control on the page. Well, that's where I went with. I decided to build the extension methods, which will include the link. Update: I had to change the ScriptManager extension because it was still not playing well with UpdatePanels, the updated code is below. & lt; link & gt; Tag in ScriptManager.RegisterClientScriptBlock (), but I get this error:
& lt; System Runtime COMPLETER SERVICES Extension () & gt; _ Public Sub RegisterStylesheetInclude (as ByVal scriptManager ScriptManager, as ByVal URL, ByVal as the page page) Dim CSS = "on cssNode = document.createElement ('click');" & Amp; _ "CssNode.type = 'text / css';" & Amp; _ "CssNode.rel = 'stylesheet';" & Amp; _ "CssNode.href = '" & amp; Url & amp; "'," & Amp; _ "Document.getElementsByTagName ('Head') [0] .appendChild (cssNode);" ScriptManager.RegisterClientScriptBlock (page, page.GetType (), URL, CSS, this is true) End Sub & LT; System.Runtime.CompilerServices.Extension () & gt; _ Public Sub RegisterStylesheetInclude (ByVal clientScriptManager as ClientScriptManager, as ByVal page page, ByVal URL string as found) = page.Header.Controls.OfType (HtmlLink) .Any (function (m) m.Href = Url) If not found then the dim link () link.href = url link.Attributes ("type") = "text / css" link.Attributes ("rel") = "stylesheet" page.Header as the new HtmlLink .Controls.Add end if the last sub
Comments
Post a Comment