locked
Custom Control CSS & UserControl RRS feed

  • Question

  • User-667042492 posted

    Hi everyone,

    i have a custom control, and it has some embedded js,image and css files.. in an aspx page everything works

    but in an ascx control, css and image files dont work, only js files works.. i register script with

    RegisterClientScriptResource mothod.. but i register css file like below;

    1    string cssTemplate = "<link rel='stylesheet' text='text/css' href='{0}' />";
    2    string cssRes = cs.GetWebResourceUrl(this.GetType(), resourceName);
    3    LiteralControl css = new LiteralControl(String.Format(cssTemplate, cssRes));
    4    this.Page.Header.Controls.Add(css);
    

    i think usercontrol can not find css location..

    Any suggestion ??

    thanks..

    Saturday, June 14, 2008 8:45 AM

Answers

  • User-16411453 posted

     It's kind of like XML, in which the tag has attributes.  Will render properly in both XHTML and HTML 4.0. You can replace the property with embedded CSS File

    Dim IncludeCss As HtmlControls.HtmlLink
    IncludeCss = New HtmlControls.HtmlLink
    IncludeCss.Attributes.Add("type", "text/css")
    IncludeCss.Attributes.Add("rel", "stylesheet")
    IncludeCss.Attributes.Add("href", [CssStyleSheet_Url])
    Me.Page.Header.Controls.Add(IncludeCss)
     
    <Bindable(True)> _
    <Browsable(True)> _
    <Description("Select the path to a Seperate CSS StyleSheet file, that your MenuItems will inherit. This StyleSheet will be loaded at run time, and automatically added to your WebForm Header tag")> _
    <Category("Appearance")> _
    <DefaultValue("")> _
    <Localizable(True)> _
    <RefreshProperties(RefreshProperties.Repaint)> _
    <EditorAttribute(GetType(System.Web.UI.Design.UrlEditor), GetType(UITypeEditor))> _
    Property CssStyleSheet_Url() As String

    Get
    Dim
    sCssStyleSheet_Url As String = CStr(ViewState("CssStyleSheet_Url"))
    If sCssStyleSheet_Url Is Nothing Then
    Return String
    .Empty
    Else
    Return
    sCssStyleSheet_Url
    End If
    End Get

    Set
    (ByVal Value As String)
    ViewState("CssStyleSheet_Url") = Value
    End Set

    End Property
       
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 17, 2008 6:32 PM