Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it L'avatar di 7vite
    Registrato dal
    Mar 2001
    Messaggi
    3,407

    Impostare dinamicamente un CSS per un tag DIV

    Ho letto questa discussione ma la soluzione non mi funziona.

    Dato un codice html del genere:
    codice:
    <div id="header" runat="server">
        ...
    </div>
    Come inizializzo header in VB?
    codice:
    header.Attributes.Add("class", "StyleRed")
    Il CSS ...
    codice:
    .StyleRed {
    		background-image: url(img/sfondo_rosso.gif);
    		height: 96px;
    	}
    Grazie.

  2. #2
    sub Page_Load
    header.Attributes.Add( "class", "StyleRed" )
    end sub

    ...a me funziona...
    "...non è detto che sia tardi se non guardi che ora è..."

  3. #3
    Utente di HTML.it L'avatar di 7vite
    Registrato dal
    Mar 2001
    Messaggi
    3,407
    Originariamente inviato da Raffa62
    sub Page_Load
    header.Attributes.Add( "class", "StyleRed" )
    end sub

    ...a me funziona...
    coma fa a non darti: Nome "header" non dichiarato ???

  4. #4
    Originariamente inviato da 7vite
    coma fa a non darti: Nome "header" non dichiarato ???
    questione di classe ...

    non sò, ci sarà un qualche errorino nel codice, vedi questo esempio

    http://www.raffaellosartori.it/settevite.aspx

    il codice è semplicemente questo

    codice:
    <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
    
    <script runat="server">
    	
    	sub Page_Load
    		header.Attributes.Add( "class", "StyleRed" )
    	end sub
    	
    	sub red( s as Object, e as EventArgs )
    		header.Attributes.Add( "class", "StyleRed" )
    	end sub
    	
    	sub orange( s as Object, e as EventArgs )
    		header.Attributes.Add( "class", "StyleOrange" )
    	end sub
    	
    	sub black( s as Object, e as EventArgs )
    		header.Attributes.Add( "class", "StyleBlack" )
    	end sub
    	
    	sub green( s as Object, e as EventArgs )
    		header.Attributes.Add( "class", "StyleGreen" )
    	end sub
    
    </script>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Documento senza titolo</title>
    <style type="text/css">
    <!--
    .StyleRed {
    	height: 96px;
    	font-family: Verdana, Arial, Helvetica, sans-serif;
    	font-size: 12px;
    	font-weight: bold;
    	color: #FF0000;
    }
    .StyleOrange {
    	height: 96px;
    	font-family: Verdana, Arial, Helvetica, sans-serif;
    	font-size: 12px;
    	font-weight: bold;
    	color: #FF9900;
    }
    .StyleBlack {
    	height: 96px;
    	font-family: Verdana, Arial, Helvetica, sans-serif;
    	font-size: 12px;
    	font-weight: bold;
    	color: #000000;
    }
    .StyleGreen {
    	height: 96px;
    	font-family: Verdana, Arial, Helvetica, sans-serif;
    	font-size: 12px;
    	font-weight: bold;
    	color: #009966;
    }
    -->
    </style>
    </head>
    <body>
    <form runat="server" id="myForm">
    <div id="header" runat="server">
        ciao mondo
    </div>
    <asp:Button ID="btnN" Text="RedStyle" OnClick="red" runat="server" />
    <asp:Button ID="btnO" Text="OrangeStyle" OnClick="orange" runat="server" />
    <asp:Button ID="btnB" Text="BlackStyle" OnClick="black" runat="server" />
    <asp:Button ID="btnG" Text="GreenStyle" OnClick="green" runat="server" />
    </form>
    </body>
    </html>
    "...non è detto che sia tardi se non guardi che ora è..."

  5. #5
    Utente di HTML.it L'avatar di 7vite
    Registrato dal
    Mar 2001
    Messaggi
    3,407
    Questo asp.net mi sta togliendo l'aria.

    E se volessi inserire il codice nel file settevite.aspx.vb?

    (per ora non mi esegue la Page_Load :rollo: )

  6. #6
    Utente di HTML.it L'avatar di 7vite
    Registrato dal
    Mar 2001
    Messaggi
    3,407
    Bastava definire header come:

    codice:
    Protected WithEvents header As System.Web.UI.HtmlControls.HtmlGenericControl

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.