JavaScript Editor
JavaScript Debugger|
| ||
You can see the Literal class at work in the Literals example on the CD-ROM. When you click the button in this example, the code inserts the HTML needed to display the word "Hello" in a centered HTML <h1> header—<div align='center'> <h1>Hello</h1></div>—into the Web form, as you can see in Figure 15.10.
Here's Webform1.aspx from the Literals example:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind=
"WebForm1.aspx.vb" Inherits="Literals.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id=Button1 style="Z-INDEX: 101; LEFT: 96px;
POSITION: absolute; TOP: 106px" runat="server" Text="Click me">
</asp:Button>
<asp:Literal id=Literal1 runat="server"></asp:Literal>
</form>
</body>
</HTML>
And here's WebForm1.aspx.vb from the same project:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents Literal1 As System.Web.UI.WebControls.Literal
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Literal1.Text = "<div align='center'><h1>Hello</h1></div>"
End Sub
End Class
Here's how the code inserts the <h1> header when you click the button in this example:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Literal1.Text = "<div align='center'><h1>Hello</h1></div>"
End Sub
|
| ||
Free JavaScript Editor
JavaScript Editor