ASP.NET: Server Roundtrip e ViewState – Codice sorgente dell’esempio

Sorgenti: viewState.aspx

Scarica i sorgenti: aspnet03.zip

Articolo a cui si riferisce il codice: ASP.NET: Server Roundtrip e ViewState

viewState.aspx – Prova l’esempio [nuova finestra]

  1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3 
  4 <%@Page Language="VB"%>
  5 <%@Register TagPrefix="ANet" TagName="Footer" Src="includes/footer.ascx"%>
  6 
  7 <!
  8 # nome: ViewState.aspx
  9 # scritto da: Antonio Volpon
 10 # data creazione: 22 Novembre 2001
 11 # ultima modifica: 22 Novembre 2001
 12 # copyright: Antonio Volpon
 13 >
 14 
 15 <script language="vb" runat="server">
 16 Sub Page_Load(sender as Object, e as EventArgs)
 17   
 18   If ViewState("colore") = "<font color=‘red’><b>Rosso</b></font>" Then
 19     colore.InnerHtml = "<font color=‘black’><b>Nero</b></font>"
 20     ViewState("colore") = "<font color=‘black’><b>Nero</b></font>"
 21   Else
 22     colore.InnerHtml = "<font color=‘red’><b>Rosso</b></font>"  
 23     ViewState("colore") = "<font color=‘red’><b>Rosso</b></font>"
 24   End If
 25   
 26   If IsNothing(ViewState("count")) Then
 27     ViewState("count") = 1            
 28   Else
 29     ViewState("count") += 1
 30   End If
 31   
 32 End Sub
 33 </script>
 34 
 35 <html>
 36   <head>
 37     <link rel="stylesheet" href="css/aspnet.css" type="text/css">
 38     </link>
 39     <title>ViewState</title>
 40   </head>
 41   <body>
 42   
 43     <div class="titolo">
 44       ViewState
 45     </div>
 46     
 47     <hr noshade="true" size="1" width="100%">
 48 
 49     <center>    
 50     
 51     <div id="colore" runat="server" class="risposta"></div>
 52     
 53     <br /><br />
 54     <span class="txt">Il contatore segna <span id="contatore" runat="server" class="txtb"><%=ViewState("count")%></span> volte.</span>
 55     
 56     <form runat="server">
 57       <input type="submit" value="Riprova">
 58     </form>
 59 
 60     </center>
 61 
 62  <ANet:Footer id="Menu" runat="server" />
 63     
 64   </body>
 65 </html>
 66   
 67