ASP.NET - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

ASP.NET Forms

ASP.NET Forms

shape Description

In ASP.NET all server controls should always appear within a form tag. That is ASP.NET Forms. [html] <form runat=”server”> <asp:control_name id="control_id" runat="server" /> </form> [/html] In the above code, one can see server control is placed between form tags. The form tag must contain the runat=”server” attribute. ASP.NET automatically adds ‘name’, ‘method’, ‘Id’ attributes to the form if these attributes are not added by the user.

shape Steps

Let's look into the steps to create a web form.

shape Step 1

Go to 'Solution Explorer' and right click on the solution. Which, one want to add the master page. Now select 'Add', go to 'New Item' and click on it.

shape Step 2

Now, a pop-up will appear asking, to choose the item. Which, one want to add. Select 'Web Form'. Give a 'Name' to it and click on 'Add'.

shape Step 3

A Web Form, 'SPWebForm.aspx' is added to the solution.

Submitting a Form

Submission of a form is mostly done by clicking of a button. [html] <asp:Button id="spButton" text="Submit" OnClick="sub" runat="server" /> [/html]

shape Step 4

In the above code, the button control is used. The button id is “spButton” having text “Submit”. On the click of the button the button click will run and form will be submitted. The “OnClick” property allows the method “sub” to execute, which submits the form. In the below example, one can see a basic form with basic controls.

shape Step 5

Here one have used label, textbox, radio button, dropdown list, checkbox list and two buttons. Submit button will submit the form and reset button will clear all the entries to the form. For validation control, one have to use RequiredFieldValidator for the controls textbox, radio button, dropdown list. Submit button will not allow the user to submit the form without filling those values in the mentioned controls.