Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Asp.Net 2.0 Presentation


Published on

Published in: Technology
  • Be the first to comment

Asp.Net 2.0 Presentation

  1. 1. ASP.NET 2.0 Overview
  2. 2. Agenda <ul><li>Web development using Visual Studio </li></ul><ul><li>Page Inheritance model </li></ul><ul><li>Deployment model </li></ul><ul><li>Master Pages </li></ul><ul><li>Themes </li></ul><ul><li>Miscellaneous </li></ul><ul><li>Summary </li></ul><ul><li>Questions </li></ul>
  3. 3. Web development using Visual Studio <ul><li>Directory Based Project System Model </li></ul><ul><ul><li>Edit any web anywhere (no project file required) </li></ul></ul><ul><ul><li>No longer required to build entire site into a single DLL </li></ul></ul><ul><ul><li>Can now re-build just individual pages to test and run </li></ul></ul><ul><li>HTML Source Preservation </li></ul><ul><ul><li>Tool will never re-format or mangle your code </li></ul></ul><ul><li>Intellisense Everywhere </li></ul><ul><ul><li>Code Behind </li></ul></ul><ul><ul><li>Inline Code </li></ul></ul><ul><li>Better code separation using folder hierarchies </li></ul><ul><ul><li>App_Code, App_LocalResources, etc. </li></ul></ul>
  4. 4. Page Inheritance model <ul><li>How does ASP.NET 1.1 model works? </li></ul><ul><ul><li>You have Code Behind file that contains all the control declarations along with code. </li></ul></ul><ul><ul><li>HTML Markup is contained in the ASPX page. </li></ul></ul><ul><ul><li>Compilation – ASPX page s compiled into a class that inherits from code behind class. </li></ul></ul><ul><li>Problems with the above model? </li></ul><ul><ul><li>Every time a change is made in ASPX page, InitializeComponent section had to be regenerated. </li></ul></ul><ul><ul><li>Try removing a control from ASPX page, most of the time VS2003 does not cleans up the code. </li></ul></ul>
  5. 5. Page Inheritance model contd … <ul><li>ASP.NET 2.0: New code-behind model </li></ul><ul><ul><li>Works using Partial Classes </li></ul></ul><ul><ul><li>Uses CodeFile attribute instead of CodeBehind </li></ul></ul><ul><ul><li>No need to explicit declaration of controls in code behind class. </li></ul></ul><ul><ul><li>So how does this works? </li></ul></ul><ul><li>Class for ASPX file generated by ASP.NET </li></ul><ul><ul><ul><li>namespace ASP </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>public class default_aspx : MsdnMag.Default </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>... </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul>
  6. 6. Page Inheritance model contd … <ul><li>Sibling partial class generated by ASP.NET </li></ul><ul><ul><li>namespace MsdnMag </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><li>public partial class Default : IRequiresSessionState </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><li>protected TextBox _nameTextBox; </li></ul></ul><ul><ul><li>protected Button _enterButton; </li></ul></ul><ul><ul><li>protected Label _messageLabel; </li></ul></ul><ul><ul><li>private HtmlForm form1; </li></ul></ul><ul><ul><li>... </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>} </li></ul></ul>
  7. 7. Page Inheritance model contd … <ul><li>Codebehind partial class that you write </li></ul><ul><ul><ul><li>namespace MsdnMag </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>public partial class Default : Page </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>void _enterButton_Click(object sender, EventArgs e) </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>_messageLabel.Text = &quot;Hello there &quot; + _nameTextBox.Text + &quot;!&quot;; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul>
  8. 8. Deployment Model <ul><li>ASP.NET 2.0 comes up with new deployment modes </li></ul><ul><ul><li>All Binary </li></ul></ul><ul><ul><li>All Source </li></ul></ul><ul><ul><li>Updateable (Source Code in binary and ASPX files in source) </li></ul></ul><ul><li>All Binary </li></ul><ul><ul><li>Both Source Code and ASPX are compiled into binary. </li></ul></ul><ul><ul><li>Each folder is compiled into separate Assembly. </li></ul></ul><ul><ul><li>The ASPX pages present are just marker files and does NOT contain any code. </li></ul></ul><ul><ul><li>PrecompiledApp.config – contains version and update mode (as False) </li></ul></ul>
  9. 9. Deployment Model Contd… <ul><li>Updateable </li></ul><ul><ul><li>Source Code is compiled into binary </li></ul></ul><ul><ul><li>ASPX files remain “as is”. </li></ul></ul><ul><ul><li>Each folder is compiled into separate Assembly </li></ul></ul><ul><ul><li>The ASPX pages present contain actual code. </li></ul></ul><ul><ul><li>PrecompiledApp.config – contains version and update mode (as True) </li></ul></ul><ul><li>Source Code </li></ul><ul><ul><li>Source Code deployed “as is” </li></ul></ul><ul><ul><li>Compiled during first hit and then cached </li></ul></ul><ul><ul><li>Advantage – any code changes take effect immediately </li></ul></ul>
  10. 10. Deployment Model Contd… <ul><li>Command Line: Aspnet_compiler </li></ul><ul><ul><li>Path: C:WINDOWSMicrosoft.NETFrameworkv2.0.50727 </li></ul></ul><ul><ul><li>Usage: aspnet_compiler.exe -v /web -p &quot;D: </li></ul></ul><ul><ul><li>ApoorvTutorialASP.NET 2.0Master Pages and Themesweb&quot; c:deploy </li></ul></ul><ul><li>UI (VS2005): Build -> Publish Web Site </li></ul><ul><ul><li>Strong Naming possible during publishing. </li></ul></ul>
  11. 11. Deployment Model Contd… <ul><li>Assembly Generation and pitfalls </li></ul><ul><ul><li>Each folder is compiled into separate assembly. </li></ul></ul><ul><ul><li>E.g. Folder Hierarchy </li></ul></ul><ul><ul><li>Admin – Admin1.aspx, Admin1.aspx.cs Assembly1 </li></ul></ul><ul><ul><li>- Admin2.aspx, Admin2.aspx.cs </li></ul></ul><ul><ul><li>Mobile – Mobile1.aspx, Mobile1.aspx.cs Assembly2 </li></ul></ul><ul><ul><li>- Mobile2.aspx, Mobile2.aspx.cs </li></ul></ul><ul><ul><li>This may cause your site to fail with change in deployment mode. </li></ul></ul><ul><ul><li>Need to realize that classes are generated at runtime </li></ul></ul><ul><ul><ul><li>If the Page and the dynamically referenced UserControl (e.g. using LoadControl) are in different page, by default you cannot access the UserControl programmatically. </li></ul></ul></ul><ul><ul><ul><li>Need to use <%@ Register %> tag on the page to refer to the userControl. </li></ul></ul></ul>
  12. 12. Master Pages <ul><li>Visual Inheritance for Web Pages </li></ul><ul><li>.master file contains template used by all pages in the application. </li></ul><ul><li>Other pages are contained as controls in the Master page. </li></ul><ul><li>Content Place Holders </li></ul><ul><ul><li>Define where custom content will be placed. </li></ul></ul><ul><ul><li>Can define default content. </li></ul></ul><ul><ul><li>Can have multiple place holders per page. </li></ul></ul><ul><li>Design support in Visual Studio .NET 2005. </li></ul>
  13. 13. Master Pages contd… <ul><li><%@ Master %> tag denotes Master page. </li></ul><ul><li><asp:contentplaceholder id=&quot;MainContentPlaceHolder&quot; runat=&quot;server&quot;> < / asp:contentplaceholder > tag denotes the place holder for the contents. </li></ul><ul><li>Content Page </li></ul><ul><ul><li>Specify the Master page using the “MasterPageFile” attribute in the <%@ Page %> tag. </li></ul></ul><ul><ul><li><asp:Content ContentPlaceHolderID=MainContentPlaceHolder ID=mainContent runat=server> CONTENTS < / asp:Content > - contents are placed within above tag. </li></ul></ul><ul><ul><li>Nesting of master pages is also possible. </li></ul></ul>
  14. 14. Themes <ul><li>Personalization of Web Pages </li></ul><ul><li>Works using .skin files </li></ul><ul><li>Place .skin file in App_Themes folder </li></ul><ul><li>Set the Theme property on the page. </li></ul><ul><ul><li>Can be set using “ Theme ” attribute of <%@ Page %> tag </li></ul></ul><ul><li>Can set Theme property programmatically as well. </li></ul><ul><ul><li>Has to be done on or before the Page_PreInit </li></ul></ul><ul><li>Sample .skin file </li></ul><ul><ul><li><asp:Label Runat=&quot;server&quot; ForeColor=&quot;Blue&quot; Font--Names=&quot;Verdana&quot; </li></ul></ul><ul><ul><li>Font-Size=&quot;Small&quot;/> </li></ul></ul>
  15. 15. Miscellaneous Lets look at some more features provided by ASP.NET 2.0 <ul><li>Setting default focus </li></ul><ul><ul><li>Page.SetFocus() </li></ul></ul><ul><ul><li>Java Script rendered on browser is: </li></ul></ul><ul><ul><li><script type=&quot;text/JavaScript&quot;> </li></ul></ul><ul><ul><li><!-- </li></ul></ul><ul><ul><li>WebForm_AutoFocus('ctl00_MainContentPlaceHolder_ddlName');// --> </li></ul></ul><ul><ul><li></script> </li></ul></ul><ul><li>Setting default button (for Enter Key) </li></ul><ul><ul><li>Panel.DefaultButton </li></ul></ul><ul><ul><li>Designates button to be &quot;clicked&quot; when Enter is pressed with focus in panel </li></ul></ul><ul><ul><li><asp:Panel DefaultButton=“Button ID”…. </li></ul></ul>
  16. 16. Miscellaneous contd… <ul><li>Cross Page Posting </li></ul><ul><ul><li>Pages can now post back to other pages </li></ul></ul><ul><ul><li>Relevant properties: </li></ul></ul><ul><ul><ul><li>control .PostBackUrl - Identifies postback target </li></ul></ul></ul><ul><ul><ul><li>Page.PreviousPage - Returns reference to page that originated a cross-page postback </li></ul></ul></ul><ul><ul><ul><li>PreviousPage.IsCrossPagePostBack - Reveals whether a cross-page postback occurred </li></ul></ul></ul><ul><ul><li>@ PreviousPageType directive provides strongly typed access to previous page </li></ul></ul><ul><ul><li>Reference previous page control in the new page </li></ul></ul>
  17. 17. Miscellaneous contd… <ul><li>E.g. </li></ul><ul><li><asp:Button ID=&quot;btnThemes&quot; runat=server Text=&quot;Themes and Skins&quot; PostBackUrl=&quot;~/Personal.aspx&quot;/> </li></ul><ul><li>Referencing Previous Page’s Controls </li></ul><ul><ul><li>Using PreviousPage object. </li></ul></ul><ul><ul><li>PreviousPage.IsCrossPagePostBack </li></ul></ul><ul><ul><li>Weak Typing </li></ul></ul><ul><ul><ul><li>PreviousPage .FindControl() </li></ul></ul></ul><ul><ul><li>Strong Typing </li></ul></ul><ul><ul><ul><li><%@ PreviousPageType VirtualPath=&quot;~/Default.aspx&quot; %> </li></ul></ul></ul><ul><ul><ul><li>PreviousPage .<<Property>> </li></ul></ul></ul>
  18. 18. Summary <ul><ul><li>New Page Inheritance Model in ASP.NET 2.0 </li></ul></ul><ul><ul><li>Various Deployment Modes available with .NET 2.0 </li></ul></ul><ul><ul><li>Master Page for consistent UI </li></ul></ul><ul><ul><li>Web page / site personalization using Themes. </li></ul></ul><ul><ul><li>Various controls / features available to reduce coding efforts </li></ul></ul>
  19. 19. References <ul><ul><li>For Page Inheritance and Deployment Model </li></ul></ul><ul><ul><ul><li> </li></ul></ul></ul><ul><ul><ul><li> </li></ul></ul></ul>
  20. 20. <ul><li>Questions </li></ul>