JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Literals

Visual Basic also gives you a way of adding HTML in a Web page while using a standard Visual Basic IDE code designer (that is, without having to switch to the .aspx page and click the HTML button to edit the HTML directly)—you can use a Literal Web server control. You just assign text to a literal control's Text property, and that text is inserted directly into the Web form. Here's the class hierarchy of this class:

Object
   Control
      Literal

This control doesn't have any visual appearance in a Web page—you just set the Text property, and that text is inserted into the Web form. For example, here's how I insert the HTML for an <h1> header into a Web form, using a literal:

Literal1.Text = "<div align='center'><h1>Hello</h1></div>"

The only part of this literal control that appears in the final Web form is the HTML:

<div align='center'><h1>Hello</h1></div>
Tip 

Note the quoted text "<div align=' center'><h1>Hello</h1></div>" that I'm assigning to the Text property here. When you quote HTML that itself contains quotes, as in this case, you should make sure that you make the inner quotes into single quotes (') so VB .NET doesn't get confused about where your quoted text ends. Note that the Unix way of doing this, which is to "escape" double as \" instead of just ", won't work here.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor