Chapter 2.0 Understanding Asp.Net Controls

Add to Favourites
Post to:
Join the .NET Community

Description
Describes asp.net controls fundamentals.

Comments
Presentation Transcript Presentation Transcript

Chapter 2.0 Understanding Controls : Chapter 2.0 Understanding Controls

Slide 2 : ASP.NET - Server Controls 1) Server controls are tags that are understood by the server. 2) There are three kinds of server controls: 2.1) HTML Server Controls - Traditional HTML tags 2.2) Web Server Controls - New ASP.NET tags ASP.NET - HTML Server Controls 1) HTML server controls are HTML tags understood by the server. 2) HTML elements in ASP.NET files are, by default, treated as text. To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server control. The id attribute is added to identify the server control. The id reference can be used to manipulate the server control at run time. Note: All HTML server controls must be within a tag with the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts.

Slide 3 : In the following example we declare an HtmlAnchor server control in an .aspx file. Then we manipulate the HRef attribute of the HtmlAnchor control in an event handler (an event handler is a subroutine that executes code for a given event). The Page_Load event is one of many events that ASP.NET understands: Test1.aspx < html>< body>< form runat="server">< a id="link1" runat="server">Visit W3Schools!< /form>< /body>< /html> Test1.aspx.cs protected void Page_Load(object sender, EventArgs e) { link1.HRef=http://www.w3schools.com }

Slide 4 : ASP.NET - Web Server Controls 1) Web server controls are special ASP.NET tags understood by the server. 2) Like HTML server controls, Web server controls are also created on the server and they require a runat="server" attribute to work. However, Web server controls do not necessarily map to any existing HTML elements and they may represent more complex elements. The syntax for creating a Web server control is: In the following example we declare a Button server control in an .aspx file. Then we create an event handler for the Click event which changes the text on the button: Test2.aspx < html>< body>< form runat="server">< asp:Button id="button1" Text="Click me!"runat="server" OnClick="submit"/> < /form>

Slide 5 : Test2.aspx.cs Protected void submit(Source As Object, e As EventArgs) { button1.Text="You clicked me!" } HTML Controls & Server Controls HTML controls and server controls are somewhat similar, and can sometimes be used interchangeably to do the same thing. For example, and both accomplish the same task, displaying an image on a web page. HTML controls refer to HTML tags that have the runat="server" attribute. For example, is a standard HTML tag, where as is an HTML Control. Server controls refer to tags starting with and . The main advantage of using server controls over HTML controls is that they are used to provide some sort of added functionality for your ASP.NET pages, such as interactive data grids and calendars. The output code is generated dynamically from server controls, and they only output code that is compatible with the client's web browser. Server controls provide programmers with a richer set of features than HTML controls.

Slide 6 : You can use both HTML controls and server controls for just about anything. However, the main purpose of these controls is to help separate HTML presentation code from application logic code. Notice how I've said "help separate"? to completely separate them from HTML code, you need to move them to a different file. We will need to use code behind technique to accomplish this

Want to learn?

Sign up and browse through relevant courses.

Name:
Your Email:
Password:
Country:
Contact no:


Area code Number
Subjects you are interested in:
Word verification: (Enter the text as in image)


Sign Up Already a member? Sign In
I agree to WizIQ's User Agreement & Privacy Policy
Adesh Sharma
A Senior Software Engineer working in a IT company on DOTNET platform
User
1 Member Recommends
6 Followers

Your Facebook Friends on WizIQ

Give live classes, create & sell online courses

Try it free Plans & Pricing

Connect