I am new to ASP.NET and I hope someone can help me.
I have problems applying Styles from a css-file on the controls of my Class PropGridControl derived from CompositeControl. This custom control will be used in any web application so I want to define the styles in my class.
When I instanciate my Controls in the CreateChildControls(), I do something like this:
This has no effect when I use the Control in a website.
I have added the file Style.css to the project and I have set Build Action to Embedded Resource in the properties. I know I am missing something here but I don't no how to do it. How do I register the css-file to my Class?
sortep
0 Points
4 Posts
Use css for a CompositeControl
Sep 24, 2009 10:16 PM|LINK
Hello people,
I am new to ASP.NET and I hope someone can help me.
I have problems applying Styles from a css-file on the controls of my Class PropGridControl derived from CompositeControl. This custom control will be used in any web application so I want to define the styles in my class.
When I instanciate my Controls in the CreateChildControls(), I do something like this:
This has no effect when I use the Control in a website.
I have added the file Style.css to the project and I have set Build Action to Embedded Resource in the properties. I know I am missing something here but I don't no how to do it. How do I register the css-file to my Class?
I hope someone can help.
Thanks,
sortep.
Abdulla.Abde...
Contributor
5538 Points
871 Posts
Re: Use css for a CompositeControl
Sep 25, 2009 11:23 AM|LINK
http://weblogs.asp.net/abdullaabdelhaq/archive/2009/09/26/how-to-embedded-stylesheet-file-with-custom-control.aspx
Abdulla Abdelhaq .NET/SharePoint Team Leader
My Articles
blog
sortep
0 Points
4 Posts
Re: Use css for a CompositeControl
Oct 04, 2009 11:41 AM|LINK
Thanks,
this worked great.
But where can I "mark as answered"?
Zap_Man
Member
35 Points
33 Posts
Re: Use css for a CompositeControl
Nov 09, 2012 01:53 AM|LINK
Hey Realy Need some Help...
I have Been stuck on this for a long time. I have went through tutorial after tutorial after tutorial. Done excatly what they all say to do.
I need to embed js, css, and images into my custom controls.
my assemply name is RTG.SiteTools
my default namespance is RTG.SiteTools.WebControls
here is a simple control
namespace RTG.SiteTools.WebControls { public class Label : System.Web.UI.Control { public string Text{get;set;} public string TipTitle{get;set;} public string TipContent{get;set;} protected override void OnInit(EventArgs e) { base.OnInit(e); string css = "<link href=\"" + Page.ClientScript.GetWebResourceUrl(this.GetType(), "RTG.SiteTools.WebControls.ToolTips.css") + "\" type=\"text/css\" rel=\"stylesheet\" />"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "tooltips", css, false); } protected override void Render(System.Web.UI.HtmlTextWriter writer) { base.Render(writer); System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image(); img.ImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(RTG.SiteTools.WebControls.Label), @"RTG.SiteTools.WebControls.Info.png"); writer.Write(String.Format(@" <a class='tooltip' href='#' tabindex='-1' onclick='return false'><b>{0}</b> <span id='tooltipSpan' class='custom info'> <img class='tooltip' src='{1}' alt='Information' height='48' width='48' /> <em class='tooltip'>{2}</em> {3} </span> </a>", Text, img.ImageUrl, TipTitle, TipContent)); } } }in my assemblyInfo file
[assembly: WebResource("RTG.SiteTools.WebControls.Info.png", "img/png")]
[assembly: WebResource("RTG.SiteToolsWebControls.ToolTips.css", "text/css")]
Thanks
Zap_Man
Member
35 Points
33 Posts
Re: Use css for a CompositeControl
Nov 09, 2012 02:55 AM|LINK
I finnaly figured it out.
I put the image and css in a directory each. Not one person mentioned that you need the namespace.(path).filename
so when I referene it in the assembly as well as in the ClientScript it would read.
[assembly: WebResource("RTG.SiteTools.WebControls.Images.Info.png", "img/png")]
Guess I am the only one that does not like all my files in the root.