If you don’t see the message with the date and time appear or you get an error on the page in
the browser, make sure you saved the changes to all open pages. To save all pages at once, press
Ctrl+Shift+S or click the Save All button on the toolbar (the one with the multiple fl oppy disk
symbols). Additionally, make sure you typed the code for the right language. When you created
this new page, you chose a programming language that applies to the entire page. You can’t mix
languages on a single page, so if you started with a Visual C# page, make sure you entered the C#
code snippet in step 6.
9. Setting up a page with inline code is very similar. Start by adding a new Web Form to the Demos
folder. Call it CodeInline.aspx and make sure you uncheck the Place Code in Separate File
option.
10. Just as you did in steps 3, 4, and 5, switch the page into Design View, drag a label inside the
element, and double-click the page somewhere outside the that now contains the label.
Instead of opening a Code Behind file, VS now switches your page into Markup View and adds the
Page_Load code directly in the page.
11. On the empty line in the code block that VS inserted, type the bolded line you see in step 6 of this
exercise. Make sure you use the correct programming language. You should end up with the following
code at the top of your .aspx file:
VB.NET
Protected Sub Page_Load(sender As Object, e As EventArgs)
Label1.Text = "Hello World; the time is now " & DateTime.Now.ToString()
End Sub
C#
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "Hello World; the time is now " + DateTime.Now.ToString();
}
12. Right-click the page in the Solution Explorer and choose View in Browser. Alternatively, press
Ctrl+F5 to open the page in your browser. You should see a page similar to the one you got in step 7.
How It Works
At run time, pages with inline code behave the same as pages that use Code Behind. In both cases, the
ASP.NET run time sees the Page_Load code and executes any code it finds in it. In the Try It Out, this