Results 1 to 7 of 7

Thread: Change border properties of ASCX from code-behind?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    41

    Change border properties of ASCX from code-behind?

    Hi
    I am building a library of asp.net user controls which I am deriving from a custom UserControlBase class which further derives from actual UserControl class. Hierarchy looks like this :

    ASCX -> UserControlBase : UserControl

    I have this requirement to put a border around all the ASCX's. So, I thought if I can modify UserControlBase it will apply to all ASCXs. I tried following code in Page_Load of UserCOntrolBase but its not working

    Code:
    this.Attributes.Add("style", "border-color:#FFFF66;border-width:4px;border-style:Dashed;");
    What should I do to make it work? Please advise.

    Thanks
    AJ
    Last edited by mittalpa; Feb 25th, 2010 at 02:13 PM. Reason: format code

  2. #2
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Change border properties of ASCX from code-behind?

    You'd need to apply a css style to a html element that wraps around all rendered html of that control. If your library has literal, label, gridview etc what html element would your style be applied to? Have you looked in the browser page source to see if you style apears at all?

  3. #3

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    41

    Re: Change border properties of ASCX from code-behind?

    no, the style does not get applied and does not come to browser. yes, somehow I need to inject a div around the webcontrol.

  4. #4
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Change border properties of ASCX from code-behind?

    When you said custom control I thought you meant literaly a "custom server control" not userControls, my mistake. If your overriding RenderControl in your class that inherits usercontrol you should be able to inject your div tag there - that's just a guess

  5. #5
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Change border properties of ASCX from code-behind?

    I wanted to try it and here is a basic example that works

    Code:
    Imports Microsoft.VisualBasic
    
    Public Class uc_base
        Inherits System.Web.UI.UserControl
        
        Public Overrides Sub RenderControl(ByVal writer As System.Web.UI.HtmlTextWriter)
    
            writer.Write("<div style='border:solid 1px blue;padding:5px;'>")
            MyBase.RenderControl(writer)
            writer.Write("</div>")
    
        End Sub
    
    End Class
    If you create a usercontrol and inherit from that base then it's wrapped in a div tag

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Change border properties of ASCX from code-behind?

    Hey,

    Nice approach.

    One suggestion would be to include a public property on the base class which is CssClass, or something similar, and use this to style the border of the div. That way the end user has more control over the look and feel.

    Gary

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Change border properties of ASCX from code-behind?

    The problem is that it'll make each ASCX a block element and can mess up the page. That's a really weird request, and this shouldn't be done in the ASCX but simply via the CSS.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width