ASP .NET Web Form Fundamentals For Beginners http://www.rajpatsystems.com
ASP.NET Application An ASP.NET application is a combination of files, pages, handlers, modules, and executable code that can be invoked from a virtual directory (and, optionally, its subdirectories) on a web server. In other words, the virtual directory is the basic grouping structure that delimits an application. http://www.rajpatsystems.com
http://www.rajpatsystems.com
ASP.NET File Types http://www.rajpatsystems.com
ASP.NET Application Directories http://www.rajpatsystems.com
Server Controls • Server controls are created and configured as objects. They run on the web server and they automatically provide their own HTML output. • Server controls behave like their Windows counterparts by maintaining state and raising events that you can react to in code. • ASP.NET actually provides two sets of server- side controls that you can incorporate into your web forms. http://www.rajpatsystems.com
HTML server controls & Web controls • HTML server controls: These are server-based equivalents for standard HTML elements. – These controls are ideal if you’re a seasoned web programmer who prefers to work with familiar HTML tags (at least at first). – They are also useful when migrating ordinary HTML pages or ASP pages to ASP.NET, because they require the fewest changes. • Web controls: These are similar to the HTML server controls, but they provide a richer object model with a variety of properties for style and formatting details. – They also provide more events and more closely resemble the controls used for Windows development. – Web controls also feature some user interface elements that have no direct HTML equivalent, such as the GridView, Calendar, and validation controls. http://www.rajpatsystems.com
HTML Server Controls • HTML server controls provide an object interface for standard HTML elements. They provide three key features: • They generate their own interface: You set properties in code, and the underlying HTML tag is created automatically when the page is rendered and sent to the client. • They retain their state: Because the Web is stateless, ordinary web pages need to do a lot of work to store information between requests. – HTML server controls handle this task automatically. For example, if the user selects an item in a list box, that item remains selected the next time the page is generated. – Or, if your code changes the text in a button, the new text sticks the next time the page is posted back to the web server. • They fire server-side events: For example, buttons fire an event when clicked, text boxes fire an event when the text they contain is modified, and so on. – Your code can respond to these events, just like ordinary controls in a Windows application. In ASP code, everything is grouped into one block that executes from start to finish. – With event-based programming, you can easily respond to individual user actions and create more structured code. – If a given event doesn’t occur, the event-handler code won’t be executed. http://www.rajpatsystems.com
The HTML Control Classes http://www.rajpatsystems.com
http://www.rajpatsystems.com
http://www.rajpatsystems.com
Important HTML Control Properties http://www.rajpatsystems.com
http://www.rajpatsystems.com
How ASP .NET Application Works • First, the request for the page is sent to the web server. If you’re running a live site, the web server is almost certainly IIS. If you’re running the page in Visual Studio, the request is sent to the built-in test server. • The web server determines that the .aspx file extension is registered with ASP.NET and passes it to the ASP.NET worker process. If the file extension belonged to another service (as it would for .asp or .html files), ASP.NET would never get involved. • If this is the first time a page in this application has been requested, ASP.NET automatically creates the application domain. It also compiles all the web page code for optimum performance, and caches the compiled files in the directory c:Windows Microsoft.NETFrameworkv2.0.50727Temporary ASP.NET Files. If this ask has already been performed, ASP.NET will reuse the compiled version of the page. • The compiled aspx page acts like a miniature program. It starts firing events (most notably, the Page.Load event). However, you haven’t created an event handler for that event, so no code runs. At this stage, everything is working together as a set of in-memory .NET objects. • When the code is finished, ASP.NET asks every control in the web page to render itself into the corresponding HTML markup. • The final page is sent to the user, and the application ends. http://www.rajpatsystems.com
http://www.rajpatsystems.com
The HtmlControl Base Class • Every HTML control inherits from the base class HtmlControl. This relationship means that every HTML control will support a basic set of properties and features. http://www.rajpatsystems.com
http://www.rajpatsystems.com
http://www.rajpatsystems.com
The HtmlContainerControl Class • Any HTML control that requires a closing tag inherits from the HtmlContainer class (which in turn inherits from the more basic HtmlControl class). For example, elements such as <a>, <form>, and <div> always use a closing tag, because they can contain other HTML elements. • On the other hand, elements such as <img> and <input> are used only as stand- alone tags. Thus, the HtmlAnchor, HtmlForm, and HtmlGenericControl classes inherit from • HtmlContainerControl, while HtmlInputImage and HtmlInputButton do not. The HtmlContainer control adds two properties to those defined in HtmlControl. http://www.rajpatsystems.com
The HtmlInputControl Class • This control defines some properties that are used for the <input> element. As you’ve already learned, the <input> element can represent different controls, depending on the type attribute. The <input type="text"> element is a text box and <input type="submit"> is a button. http://www.rajpatsystems.com
The Page Class • Every web page is a custom class that inherits from System.Web.UI.Page. • By inheriting from this class, your web page class acquires a number of properties and methods that your code can use. • These include properties for enabling caching, validation, and tracing http://www.rajpatsystems.com
http://www.rajpatsystems.com
Sending the User to a New Page • Click <a href="newpage.aspx">here</a> to go to newpage.aspx. • HttpResponse.Redirect() – you can get access to the current HttpResponse object through the Page.Response property. – Response.Redirect("newpage.aspx"); – Response.Redirect("http://www.prosetech.com"); • HttpServerUtility.Transfer() – An HttpServerUtility object is provided through the Page.Server property – Server.Transfer("newpage.aspx"); http://www.rajpatsystems.com
HTML Encoding http://www.rajpatsystems.com
Application Events http://www.rajpatsystems.com
The Global.asax File • To add a Global.asax file to an application in Visual Studio, choose Website –> Add New Item, and select the Global Application Class file type. Then, click OK. http://www.rajpatsystems.com
ASP.NET Configuration • Every web application includes a web.config file that configures fundamental settings everything from the way error messages are shown to the security settings that lock out unwanted visitors. • The ASP.NET configuration files have several key advantages: – They are never locked: You can update web.config settings at any point, even while your application is running. If there are any requests currently under way, they’ll continue to use the old settings, while new requests will get the changed settings right away. – They are easily accessed and replicated: Provided you have the appropriate network rights, you can change a web.config file from a remote computer. You can also copy the web.config file and use it to apply identical settings to another application or another web server that runs the same application in a web farm scenario. – The settings are easy to edit and understand: The settings in the web.config file are humanreadable, which means they can be edited and understood without needing a special configuration tool. http://www.rajpatsystems.com
The web.config File • The web.config file uses a predefined XML format. The entire content of the file is nested in a root <configuration> element. Inside this element are several more subsections, some of which you’ll never change, and others which are more important. http://www.rajpatsystems.com
Nested Configuration • ASP.NET uses a multilayered configuration system that allows you to set settings at different levels. – Every web server starts with some basic settings that are defined in two configuration files in the c:WindowsMicrosoft.NETFrameworkv2.0.50727Config directory. – These two files are machine.config and web.config. Generally, you won’t edit either of these files manually, because they affect the entire computer. Instead, you’ll configure the web.config file in your web application folder. Using that file, you can set additional settings or override the defaults that are configured in the two system files. – More interestingly, you can use different settings for different parts of your application. To use this technique, you need to create additional subdirectories inside your virtual directory. These subdirectories can contain their own web.config files with additional settings. http://www.rajpatsystems.com
http://www.rajpatsystems.com
Storing Custom Settings in the web.config File • ASP.NET also allows you to store your own settings in the web.config file, in an element called <appSettings>. Note that the <appSettings> element is nested in the root <configuration> element. http://www.rajpatsystems.com
The custom settings that you add are written as simple string variables. You might want to use a special web.config setting for several reasons: – To centralize an important setting that needs to be used in many different pages: For example, you could create a variable that stores a database query. Any page that needs to use this query can then retrieve this value and use it. – To make it easy to quickly switch between different modes of operation: For example, you might create a special debugging variable. Your web pages could check for this variable and, if it’s set to a specified value, output additional information to help you test the application. – To set some initial values: Depending on the operation, the user might be able to modify these values, but the web.config file could supply the defaults. • You can enter custom settings using an <add> element that identifies a unique variable name (key) and the variable contents (value). http://www.rajpatsystems.com
http://www.rajpatsystems.com
http://www.rajpatsystems.com

Asp .net web form fundamentals

  • 1.
    ASP .NET Web FormFundamentals For Beginners http://www.rajpatsystems.com
  • 2.
    ASP.NET Application An ASP.NETapplication is a combination of files, pages, handlers, modules, and executable code that can be invoked from a virtual directory (and, optionally, its subdirectories) on a web server. In other words, the virtual directory is the basic grouping structure that delimits an application. http://www.rajpatsystems.com
  • 3.
  • 4.
    ASP.NET File Types http://www.rajpatsystems.com
  • 5.
    ASP.NET Application Directories http://www.rajpatsystems.com
  • 6.
    Server Controls • Servercontrols are created and configured as objects. They run on the web server and they automatically provide their own HTML output. • Server controls behave like their Windows counterparts by maintaining state and raising events that you can react to in code. • ASP.NET actually provides two sets of server- side controls that you can incorporate into your web forms. http://www.rajpatsystems.com
  • 7.
    HTML server controls& Web controls • HTML server controls: These are server-based equivalents for standard HTML elements. – These controls are ideal if you’re a seasoned web programmer who prefers to work with familiar HTML tags (at least at first). – They are also useful when migrating ordinary HTML pages or ASP pages to ASP.NET, because they require the fewest changes. • Web controls: These are similar to the HTML server controls, but they provide a richer object model with a variety of properties for style and formatting details. – They also provide more events and more closely resemble the controls used for Windows development. – Web controls also feature some user interface elements that have no direct HTML equivalent, such as the GridView, Calendar, and validation controls. http://www.rajpatsystems.com
  • 8.
    HTML Server Controls • HTML server controls provide an object interface for standard HTML elements. They provide three key features: • They generate their own interface: You set properties in code, and the underlying HTML tag is created automatically when the page is rendered and sent to the client. • They retain their state: Because the Web is stateless, ordinary web pages need to do a lot of work to store information between requests. – HTML server controls handle this task automatically. For example, if the user selects an item in a list box, that item remains selected the next time the page is generated. – Or, if your code changes the text in a button, the new text sticks the next time the page is posted back to the web server. • They fire server-side events: For example, buttons fire an event when clicked, text boxes fire an event when the text they contain is modified, and so on. – Your code can respond to these events, just like ordinary controls in a Windows application. In ASP code, everything is grouped into one block that executes from start to finish. – With event-based programming, you can easily respond to individual user actions and create more structured code. – If a given event doesn’t occur, the event-handler code won’t be executed. http://www.rajpatsystems.com
  • 9.
    The HTML ControlClasses http://www.rajpatsystems.com
  • 10.
  • 11.
  • 12.
    Important HTML ControlProperties http://www.rajpatsystems.com
  • 13.
  • 14.
    How ASP .NETApplication Works • First, the request for the page is sent to the web server. If you’re running a live site, the web server is almost certainly IIS. If you’re running the page in Visual Studio, the request is sent to the built-in test server. • The web server determines that the .aspx file extension is registered with ASP.NET and passes it to the ASP.NET worker process. If the file extension belonged to another service (as it would for .asp or .html files), ASP.NET would never get involved. • If this is the first time a page in this application has been requested, ASP.NET automatically creates the application domain. It also compiles all the web page code for optimum performance, and caches the compiled files in the directory c:Windows Microsoft.NETFrameworkv2.0.50727Temporary ASP.NET Files. If this ask has already been performed, ASP.NET will reuse the compiled version of the page. • The compiled aspx page acts like a miniature program. It starts firing events (most notably, the Page.Load event). However, you haven’t created an event handler for that event, so no code runs. At this stage, everything is working together as a set of in-memory .NET objects. • When the code is finished, ASP.NET asks every control in the web page to render itself into the corresponding HTML markup. • The final page is sent to the user, and the application ends. http://www.rajpatsystems.com
  • 15.
  • 16.
    The HtmlControl BaseClass • Every HTML control inherits from the base class HtmlControl. This relationship means that every HTML control will support a basic set of properties and features. http://www.rajpatsystems.com
  • 17.
  • 18.
  • 19.
    The HtmlContainerControl Class • Any HTML control that requires a closing tag inherits from the HtmlContainer class (which in turn inherits from the more basic HtmlControl class). For example, elements such as <a>, <form>, and <div> always use a closing tag, because they can contain other HTML elements. • On the other hand, elements such as <img> and <input> are used only as stand- alone tags. Thus, the HtmlAnchor, HtmlForm, and HtmlGenericControl classes inherit from • HtmlContainerControl, while HtmlInputImage and HtmlInputButton do not. The HtmlContainer control adds two properties to those defined in HtmlControl. http://www.rajpatsystems.com
  • 20.
    The HtmlInputControl Class • This control defines some properties that are used for the <input> element. As you’ve already learned, the <input> element can represent different controls, depending on the type attribute. The <input type="text"> element is a text box and <input type="submit"> is a button. http://www.rajpatsystems.com
  • 21.
    The Page Class •Every web page is a custom class that inherits from System.Web.UI.Page. • By inheriting from this class, your web page class acquires a number of properties and methods that your code can use. • These include properties for enabling caching, validation, and tracing http://www.rajpatsystems.com
  • 22.
  • 23.
    Sending the Userto a New Page • Click <a href="newpage.aspx">here</a> to go to newpage.aspx. • HttpResponse.Redirect() – you can get access to the current HttpResponse object through the Page.Response property. – Response.Redirect("newpage.aspx"); – Response.Redirect("http://www.prosetech.com"); • HttpServerUtility.Transfer() – An HttpServerUtility object is provided through the Page.Server property – Server.Transfer("newpage.aspx"); http://www.rajpatsystems.com
  • 24.
    HTML Encoding http://www.rajpatsystems.com
  • 25.
    Application Events http://www.rajpatsystems.com
  • 26.
    The Global.asax File •To add a Global.asax file to an application in Visual Studio, choose Website –> Add New Item, and select the Global Application Class file type. Then, click OK. http://www.rajpatsystems.com
  • 27.
    ASP.NET Configuration • Everyweb application includes a web.config file that configures fundamental settings everything from the way error messages are shown to the security settings that lock out unwanted visitors. • The ASP.NET configuration files have several key advantages: – They are never locked: You can update web.config settings at any point, even while your application is running. If there are any requests currently under way, they’ll continue to use the old settings, while new requests will get the changed settings right away. – They are easily accessed and replicated: Provided you have the appropriate network rights, you can change a web.config file from a remote computer. You can also copy the web.config file and use it to apply identical settings to another application or another web server that runs the same application in a web farm scenario. – The settings are easy to edit and understand: The settings in the web.config file are humanreadable, which means they can be edited and understood without needing a special configuration tool. http://www.rajpatsystems.com
  • 28.
    The web.config File •The web.config file uses a predefined XML format. The entire content of the file is nested in a root <configuration> element. Inside this element are several more subsections, some of which you’ll never change, and others which are more important. http://www.rajpatsystems.com
  • 29.
    Nested Configuration • ASP.NETuses a multilayered configuration system that allows you to set settings at different levels. – Every web server starts with some basic settings that are defined in two configuration files in the c:WindowsMicrosoft.NETFrameworkv2.0.50727Config directory. – These two files are machine.config and web.config. Generally, you won’t edit either of these files manually, because they affect the entire computer. Instead, you’ll configure the web.config file in your web application folder. Using that file, you can set additional settings or override the defaults that are configured in the two system files. – More interestingly, you can use different settings for different parts of your application. To use this technique, you need to create additional subdirectories inside your virtual directory. These subdirectories can contain their own web.config files with additional settings. http://www.rajpatsystems.com
  • 30.
  • 31.
    Storing Custom Settingsin the web.config File • ASP.NET also allows you to store your own settings in the web.config file, in an element called <appSettings>. Note that the <appSettings> element is nested in the root <configuration> element. http://www.rajpatsystems.com
  • 32.
    The custom settingsthat you add are written as simple string variables. You might want to use a special web.config setting for several reasons: – To centralize an important setting that needs to be used in many different pages: For example, you could create a variable that stores a database query. Any page that needs to use this query can then retrieve this value and use it. – To make it easy to quickly switch between different modes of operation: For example, you might create a special debugging variable. Your web pages could check for this variable and, if it’s set to a specified value, output additional information to help you test the application. – To set some initial values: Depending on the operation, the user might be able to modify these values, but the web.config file could supply the defaults. • You can enter custom settings using an <add> element that identifies a unique variable name (key) and the variable contents (value). http://www.rajpatsystems.com
  • 33.
  • 34.