20.01.2015 Views

Teach Yourself e.net - Syspro

Teach Yourself e.net - Syspro

Teach Yourself e.net - Syspro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

More Advanced Options<br />

Example 6.7. Simple Codebehind Page<br />

Imports System<br />

Imports System.Web<br />

Imports System.Web.UI<br />

Imports Encore<br />

Namespace SimpleControlSamples<br />

Public Class SimpleVB<br />

Inherits Page<br />

Protected Overrides Sub Render(Output As HtmlTextWriter)<br />

Output.Write("Welcome to Simple Codebehind!")<br />

End Sub<br />

End Class<br />

End Namespace<br />

We know that when creating a codebehind file we need to specify any namespaces for<br />

other classes that we will be using in the file. In our case we're specifying the System and<br />

System.Web.UI namespaces. We need to specify the System namespace because it<br />

includes the common classes we need to use in almost every operation. If you were using a<br />

Web Server Control in your class, you would need to reference the<br />

System.Web.UI.WebControls. We are also including the SYSPRO e.<strong>net</strong> solutions<br />

"Encore" namespace so that we can utilize the e.<strong>net</strong> solutions classes within our code.<br />

When you define your class you need to specify a class it inherits from. The Page class is<br />

associated with all files that have an .aspx extension. These files are compiled at runtime<br />

as Page objects and cached, and should be used when creating a Web Forms page with a<br />

codebehind file. At the same time we are also specifying the custom namespace<br />

(SimpleControlSamples) for the codebehind, which provides a naming scope for our class<br />

and is good way to represent a hierarchy of classes.<br />

6–15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!