iTech College - Internet Technology, Online Education, E-Learning, Technician Training, Tech Tutorials, Distance Education, Virtual Learning ASP-NET Course: ASP.NET Web Forms - www.itechcollege.com ASP-NET Course: ASP.NET Web Forms - www.itechcollege.com
Free Courses
HTML
JavaScript
CSS
ASP
PHP
JSP
C++
ASP.NET
SQL
AJAX
FTP
XML

courses > ASP-NET > ASP.NET Web Forms

ASP.NET Web Forms

We already mentioned that, all server controls must appear within <form> and </form> tags, and the <form> tag must contain the runat="server" attribute.

<form runat="server">
...HTML + server controls
</form>

Please note: Not like classic ASP or PHP, you can add an action attribute to the form, ASP.NET web form is always submitted to the page itself. If you specify an action attribute, it is alwarys ignored. If you omit the method attribute, it will be set to method="post" by default. Also, if you do not specify the name and id attributes, they are automatically assigned by ASP.NET.

A form usually must be submitted by clicking on a button. The following is Button server control in ASP .NET:

<asp:Button id="id" text="label" OnClick="sub" runat="server" />

The id attribute gives a unique name for the button and the text attribute assigns a label to the button. The onClick event handler specifies a named subroutine to execute.

ASP.NET has a default setting for web forms - Maintaining the ViewState. What is Maintaining the ViewState? Let's say, you have entered a form with a lot of information. But after click the submit button, the server comes back with an error. If the form is submitted in classic ASP, you will have to go back to the form and reenter all the information again because all form values are cleared when you submit it. But if you use ASP.NET web form, you will save a lot of coding because ASP .NET maintains your ViewState. The ViewState indicates the status of the page when submitted to the server.

Please note: Maintaining the ViewState is the default setting for ASP.NET Web Forms. If you do not want to maintain the ViewState, you must include the directive <%@ Page EnableViewState="false" %> at the top of an .aspx page or add the attribute EnableViewState="false" to any control.

See the following example:

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl1.Text="Hello " & txt1.Text & ", Welcome to iTechCollege.com!"
End Sub
</script>

<html>
<body>
<form runat="server">
Your Name: <asp:TextBox id="txt1" runat="server" />
<asp:Button OnClick="submit" Text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>
</body>
</html>



  Back to Index Page
 Next Page:  

Introduction
Server Controls
Event Handler
Web Forms
Database Connection


Online Education, Online Training for Your Job, Distance Education, E-learning Programs for Your Career!Online Colleges, Online Universities, E-learning & Distance Education for Your Career! Easy Job Training & Online Courses.


   Email A Friend  
 
Earn Online Degree
for Your Job
I found a job after I earned an online degree!
Online classes for finding a Job. Online College, Online University, Degrees, E-learning school, online certificate Earn your
online degree now!
Online Training
for Good Job
Why I work so hard but earn so little? Why I cannot find a high paying job?
Online training for a Good Jobs. Online Degree, E-learning school, online certificate Go to
online school now!

Copyright ©2024, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech