VB.Net - SPLessons

VB.Net Working with WebForms

Home > Lesson > Chapter 21
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

VB.Net Working with WebForms

VB.Net Working with WebForms

shape Description

Form is a User Interface. We have several tools to design our User Interface as more attractive. As of now SPlesson taught about the  basics of VB.Net , now it will teach how to start with web forms ,it's very interesting to create web forms. To work with forms in VB.Net, We must follow the below steps.

shape Steps

Follow the below steps to open a new Asp.Net Web Application. Click on Visual Studio 2013 Ultimate(whatever the version you have).Go to File->New->Project as shown in the below figure. Then, the New Project window will be open as shown in the below figure. Follow the steps marked in the below figure. Give the Name and Click on OK. Then, the following window will be open. Select the Webform and click on OK as marked below. Then, a new Web Application will be created as shown in the below figure. Now Add a New Webform. Go to Solution Explorer->Right click on the ApplicationName ie.ControlsExample and Add->New Item as shown in the below figure. Then, you will get Add New Item window as shown in the below figure. Click on the web and then click on Webform->Give the Name in the Name Field->Click on the Add as marked in the below figure. Then, a new web form will be added to your project.

shape Examples

Follow the below simple Example to know how to work with the web forms. Drag and Drop the Two Labels, Textbox, and Button controls onto the form and arrange the controls as shown in the below figure. OR Write the following code in the Source snippet. [html]<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Sample.aspx.vb" Inherits="ControlsExample.Sample" %&gt; <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <table width="100%"> <tr> <td style="text-align: right"> <asp:Label ID="lblName" runat="server" style="text-align: right; font-weight: 700;" Text="Enter Name:"></asp:Label></td> <td><asp:TextBox ID="txtName" runat="server" BorderColor="#000066" BorderStyle="Solid"></asp:TextBox></td> </tr> <tr> <td></td> <td> <asp:Button ID="btnSubmit" runat="server" Text="Submit" style="font-weight: 700"/> </td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td> <asp:Label ID="LblMessage" runat="server" style="font-weight: 700"></asp:Label> </td> <td></td> </tr> </table> </form> </body> </html> [/html] Double click on the Submit Button. Then the following code will be generated in the Sample.aspx.vb. [vbnet] Public Class Sample Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click End Sub End Class [/vbnet] Write the following code in the btnSubmit_Click event as shown in the below code. [vbnet] Public Class Sample Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click LblMessage.Text = "Entered Name is " + txtName.Text End Sub End Class [/vbnet] Output: Click on the Google Crome which appeared on the above in the window or press f5 to run the application.Then, Output will be generated in the browser and then Enter the Name. Then, the output will be appeared as shown in the below figure.

shape Programming Tips

  • Validation of a selected object is important.
  • The web forms application will be done ASP.Net .
  • The result will come in browser which user has chosen.