|
-
Feb 25th, 2010, 02:11 PM
#1
Thread Starter
Member
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
-
Feb 25th, 2010, 06:27 PM
#2
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?
-
Feb 25th, 2010, 10:16 PM
#3
Thread Starter
Member
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.
-
Feb 26th, 2010, 01:01 AM
#4
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
-
Feb 26th, 2010, 01:36 AM
#5
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
-
Feb 26th, 2010, 03:39 AM
#6
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
-
Feb 28th, 2010, 11:01 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|