Can a Web User Control (.ascx) use a CSS file for styling?
Asked Answered
H

3

2

Here's the source of a blank .acsx file I created called LogOnBox.

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LogOnBox.ascx.cs" Inherits="ECommerce.Views.Shared.LogOnBox" %>

I want to drag some labels, and textboxes etc and give them style using a CSS file. How can I associate a CSS to an acsx file?

Hautbois answered 27/6, 2010 at 16:55 Comment(1)
Are you using ASP.NET or ASP.NET MVC? The solution is different for each.Scrotum
W
4

The CSS is associated to the page, and not the control specifically. But you can use the CSS in the control when the page has referenced it.

Wedekind answered 27/6, 2010 at 16:59 Comment(1)
So how do you suggest I apply an html id to a part of my webcontrol?Hautbois
M
1

Just reference the css file in the header of the page containing the user control.

Manrope answered 27/6, 2010 at 16:57 Comment(1)
+1 to counter the downvote. This is true no matter how you look at it.Odense
S
0

In my cases i would like to embed css and js file into dll for do that i do bellow steps and it work

step 1 Put bellow code on top of your page behind

   [assembly:WebResource("YourProjectName.Assets.Plugins.Dropzone.dist.dropzone.js",    "application/x-javascript")]
[assembly:WebResource("YourProjectName.Assets.Plugins.Dropzone.dist.dropzone.css","text/css")]
namespace Sanay.Suip.UserControls
{
    public partial class FileUpload : UserControlBase
    {

step 2

And in inInitial event by bellow codes

`protected override void OnInit(EventArgs e)
{

base.OnInit(e);
string css = "<link href=\"" + Page.ClientScript.GetWebResourceUrl(this.GetType(),
"YourProjectName.Assets.Plugins.Dropzone.dist.dropzone.css") + "\" type=\"text/css\" rel=\"stylesheet\" />";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "cssFile", css, false);
ClientScriptManager csm = Page.ClientScript;
csm.RegisterClientScriptResource(GetType(), "YourProjectName.Assets.Plugins.Dropzone.dist.dropzone.js");
}

`

Sinistrad answered 3/11, 2016 at 10:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.