Registrar CSS mediante programación

Hola!
Le he buscado por todos lados y no le encuentro!
Tengo una clase: "PaginaAutorizada" que hereda de System. Web.UI.Page. La utilizo para heredar de ahí todas las páginas del sistema y correr métodos de validación y poner menús y submenús en el evento "override protected void OnInit(EventArgs e)".
Código:
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
this.AutorizarUsuario();
this.AgregarHojaDeEstilos();
this.AgregarTitulo();
this.AgregarSubMenu();
}
Lo único que me falta es registrar dinámicamente la hoja de estilos común en el método "AgregarHojaDeEstilos". Para no tener que cambiar cada docto aspx y poner
<LINK href="Admin/Estilos/HojaDeEstilos.css" type="text/css" rel="stylesheet">
En el encabezado.
¿Conoces la forma de hacerlo?
Gracias por adelantado
Respuesta
1
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
const string styleFormat =
"<LINK href='\"{0}\"' type='\"text/css\"' rel='\"stylesheet\"'>";
string linkText;
linkText = String.Format(styleFormat, StyleSheetPath);
StyleSheet.Text = linkText;
}
}
protected string StyleSheetPath
{
Get
{
// Pull the stylesheet name from a database or xml file...
return ApplicationPath + "MyStyle.css";
}
}
private string ApplicationPath
{
Get
{
string result = Request.ApplicationPath;
if(!result.EndsWith("/"))
{
result += "/";
}
return result;
}
}
Aquí esta el código que necesitas.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas