Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as pdf
Download as pdf
You are on page 1of 30
Unit2 Web Form Fundamentals Templates to create ASP.NET applications vi. ASP.NET Web Forms Site: A ready-made website with a main layout page, a home page, an about page, and user account pages (register, login, change password). ASP.NET Web Site (Razor): A website using the MVC (Model-View-Controller) pattern, giving you more control over IITML and better for testing. ASP.NET Empty Web Site: A basic website with only a configuration file, great for learning ASP.NET without extra files. ASP.NET Dynamic Data Entities Web Site: A website that easily connects to a database using dynamic data features. WCF Service: A set of server methods that other programs can call. ASP.NET Reports Web Site: A webs online, for creating and viewing database reports 4.2.2 Anatomy of a Webform Views of a WebForm: Design View: Drag and drop components from the toolbox and adjust their appearance and layout. Source View: Sec and edit the underlying HTML and ASP.NET control tags, Code-Behind File (.aspx.cs): Write dynamic and operational code for the web form. Key Parts of a WebForm: a) Directives: Control page compilation, navigation settings, error fixing, and class importing. Directives start with <%@ and end with %=. Example: <%@ Page Language="C#" %> specifies the programming language (C# or VB.NET) for the page. b) Doctype: Appears just below the page directive. Indicates the type of markup (HTML, XHTML) used for the web page. Influences how the browser interprets the page. Example: ¢) Web Form Markup: + Contains standard HTML tags like , , and . + Can include additional HTML elements such as paragraphs, headings, tables, etc. + Allows adding ASP.NET-specific elements. + Example: adds a label By understanding these parts, you can effectively design and code your ASP.NET web forms. 4.3 Writing Code + To write dynamic or operational code, switch to the code-behind view. + Use the View Code or View Designer buttons above the Solution Explorer. + You can also double-click the .aspx page (for design view) or the .aspx.cs page (for code view) 1. Code-Behind Class: + Code-behind is the code for an ASP.NET page written in a separate .cs file. + Ithandles events and other functions required for the page. 2. Adding Event Handlers: + ASP.NET uses an event-based model. + Example: Add a button to a Web Forms page and write a click event handler for it. + Events vriginate ui Ue client sidle but aie havadled uns Ube set ver by ASP.NET. + Event-handler methods follow a standard NET Framework pattern: © They pass two arguments * An object representing the source of the event. + Anevent object containing event-specific information, Syntax: _ private void EventName( object sender, EventArgs e ); where, object sender represents the object raising the event EventArgs represents the event arguments Ex. Select the button and right click and click on properties. In the properties window click the yellow icon event. Or simply double click the button, it will show code behind file where we can write the code if the user click button what action has to be performed. public partial class Default : System.Web.ULPage { protected void Page_Load (object sender, EventArgs ¢) { } protected void Button1_Click(object sender, EventArgs ¢) { } t @ Class Definition: + public partial class_Default :System.Web.UI.Page: This line means we are creating ‘a web page class named _Default. © Page_Luad Methud: + protected void Page_Load(object sender, EventArgs e): This method runs every time the page loads. + You can put code here to set up things when the page is first opened. @ Button1_Click Method: «protected void Button _Click(object sender, EventArgs e): This method runs when the button named Button1 is clicked. + You can put code here to define what should happen when the button is pressed. 4.4 Understanding the Anatomy of an ASP.NET Application + ASP.NET applications are divided into multiple web pages. + Allpages share common resources and configuration settings. + Each application runs in its own space, ensuring that errors in one application don't affect others. Key ASP.NET File Types ‘+ aspx: ASP.NET web pages containing the user interface. + .asex: User controls, reusable parts o' the user interface, without , , and
tags. mx: Web services for creating APIs. + web.config: XML-based configuration file managing security, state, and memory. + global.asax: Defines global variablesand handles global events. + disco or .vsdisco: Discovery files for locating web services. + vb or cs. Code-beliind files separating code from the user interface. + sin, suo: Visual Studio files grouping projects during development. Special ASP.NET Web Folders + App_Browsers: Stores browser definition files (browser) to support different browsers and mobile applications. + App_Code: Contains source code files (.cs, .vb) for utility classes and business logic, automatically compiled. + App_Data: Stores database files (.mdf, xml) for local data storage. + App_GlobalResources: Holds global resource files (.resx, resources) for text and images, supporting multiple languages. + App_LocalResources: Contains resource files for specific pages or controls, not globally accessible. + App_Themes: Includes subfolders defining themes (look and feel) with files like skin, css, and images. + App_WebReferences: Stores web reference files (.wsdl, .xsd, isco) for web services. + Bin: Contains compiled assemblies (dll) automatically referenced by the application. 4.5 Introducing Server Controls Server controls are elements on an ASP.NET page that users can interact with. They handle tasks like displaying data, capturing user put, and validating information. ‘Types of Server Controls 1, HTML Server Controls: © These are traditional HTML tags with added functionality. For example, turns a regular HTML input field into a server control. 2. Web Server Controls: © These are ASP.NET-specific controls that provide richer functionality. Examples include and . They are more powerful than regular HTML controls. 3, Validation Server Controls: © Used to check user input for correctness. Examples include and . They help ensure the data entered by users is valid before it is processed. Key Points + Within : Most server controls need to be inside a tag to function properly. Exceptions include the and . + Advantages. © Access and State: Server controls make it easy to interact with HTML elements in your code. They retain their state, so user inputs are preserved across postbacks (when a page is sent to the server and then returned to the client). © Separation of Concerns: ASP.NET controls help separate the design (HTML) from the logic (C# or VB.NET), making it easier to manage and maintain your code. 4.5.1 HTML Server Controls ‘The HTML server controls are usually considered as the standard HTML controls which are created to enable server side processing. When attribute runat="server" is added, they get converted into server control and when is attributed is added, they are available for server-side processing. All HTML server controls must be within a tag with the runat="server" attribute. ASP.NET requires that all HTML elements must be properly closed and properly nested. HtmlAnchor: Controls an HTML element (link), HtmlButton: Controls a