Home > SOA Tips > .NET Developer > Create a simple Web form page
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

.NET DEVELOPER

Create a simple Web form page


Stephen Walther
04.15.2003
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



.NET Developer Tip
(Receive this column in your inbox,
click Edit your Profile to subscribe.)

Create a simple Web form page
Stephen Walther

In a former tip, we discussed the Web form as an object. Now we go a bit further into a discussion of Web forms with this tip, excerpted from InformIT, which offers a discussion of how to create a Web form page for your project. The tip also offers two examples, one in C# and one in VB, of code that will create the Web form page.


We'll start with a simple Web Form Page. We'll create a page that randomly displays a fortune.

You should add a Web Form Page to an existing ASP.NET project. We [do that as follows].

  • Select Project, Add Web Form.
  • In the Add New Item dialog box, enter the name Fortune.aspx for the Web Form in the Name text box.
  • Click Open.

Now that you've created a Web Form Page, you can add server controls to the page from the Web Forms toolbox. We'll add a Label control to the page by performing the follow steps:

  • If the Toolbox window is not already open, select View, Toolbox.
  • Drag a Label control onto the Designer surface from under the Web Forms tab in the Toolbox.

The next step is to add some application logic to the page. We want to retrieve a random fortune from an ArrayList of fortunes and display the fortune in the Label control. To do this, perform the following steps: Double-click the Designer surface to switch to the Code Editor.
Enter the following code for the Page_Load() method:

C#
 
private void Page_Load(object sender, System.EventArgs e)
{
 // Put user code to initialize the page here
 ArrayList colFortunes = new ArrayList();
 Random objRan = new Random();

 colFortunes.Add("Good things will happen!");
 colFortunes.Add("Future looks bright!");
 colFortunes.Add("Stay in bed!");

 Label1.Text = colFortunes[ objRan.Next( 3 ) ].ToString();
}
VB.NET
Private Sub Page_Load(ByVal sender As System.Object, 
ByValue As System.EventArgs) Handles MyBase.Load
 'Put user code to initialize the page here
 Dim colFortunes As New ArrayList()
 Dim objRan As New Random()

 colFortunes.Add("Good things will happen!")
 colFortunes.Add("Future looks bright!")
 colFortunes.Add("Stay in bed!")

 Label1.Text = colFortunes(objRan.Next(3))
End Sub

Finally, we are ready to compile and view our Web Forms page. Right-click the Web Form in the Solution Explorer window and select Build and Browse. The Web Form Page will be opened in a browser and you should see a fortune. Whenever you click the Refresh button, a new fortune is randomly selected and displayed.

TIP
If you receive an error when building your code, select Build Solution from the Build menu. A list of errors in your code will pop up in the Task List window. You can double-click an error to go directly to the error in your code.


To read the article from which this tip comes, click over to InformIT. You have to register there, but the registration is free.

For More Information:

  • Looking for free research? Browse our comprehensive White Papers section by topic, author or keyword.
  • Are you tired of technospeak? The Web Services Advisor column uses plain talk and avoids the hype.
  • For insightful opinion and commentary from today's industry leaders, read our Guest Commentary columns.
  • Hey Codeheads! Start benefiting from these time-saving XML Developer Tips and .NET Developer Tips.

  • Visit our huge Best Web Links for Web Services collection for the freshest editor-selected resources.
  • Visit Ask the Experts for answers to your Web services, SOAP, WSDL, XML, .NET, Java and EAI questions.
  • Choking on the alphabet soup of industry acronyms? Visit our helpful Glossary for the latest industry lingo.
  • Couldn't attend one of our Webcasts? Don't miss out. Visit our archive to watch at your own convenience.
  • Discuss this article, voice your opinion or talk with your peers in the SearchWebServices Discussion Forums.

Rate this Tip
To rate tips, you must be a member of SearchSOA.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Microsoft .NET Web services
Microsoft preps .NET 4.0 - framework improves on REST, MVC, JQuery support
How do I balance throughput requirements and interoperability?
APM software traces transactions across tiers, technologies
How you can learn M Grammar for Oslo modeling
Legacy modernization opens Windows for publisher
Former .NET Web developers ride Ruby and Rails application framework
Microsoft Oslo at PDC: Dial 'M' for modeling language
Yahoo proxy fight looms
New Microsoft site for architects
LAMP coders go hybrid route
Microsoft .NET Web services Research

Platforms and Servers
Tracking down managed memory leaks
Handling exceptions in .NET
.NET Compact Framework graphics
The Data Access Application Block
Decision time: .NET or J2EE?
A great .NET resource: .Net2TheMax
Delegates vs. interfaces in .NET
Project structure best practices
Working with PDFs in a .NET environment
Displaying errors with the error provider

.NET Developer
Programming Indigo
DataSets and Web services don't mix
Security in .NET 2.0
Tracking down managed memory leaks
Handling exceptions in .NET
.NET Compact Framework graphics
The Data Access Application Block
A great .NET resource: .Net2TheMax
Delegates vs. interfaces in .NET
Project structure best practices

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Common Language Infrastructure  (SearchSOA.com)
Visual J#  (SearchSOA.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



SOA Trends and Strategy - SOA Education, SOA Development, SOA Implementations
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2001 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts