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

∥☆過路亽.° 提交于 2019-11-28 10:08:49

问题


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?


回答1:


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.




回答2:


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




回答3:


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");
}

`



来源:https://stackoverflow.com/questions/3128074/can-a-web-user-control-ascx-use-a-css-file-for-styling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!