LDNDeveloper

Andrew Pallant

Software & Web Developer


Donate To Support My Blog Donate if this post helped you. Coffee money is always welcomed!




Starting a WebForm Project

Physical Link: Starting a WebForm Project


    I started working in the DotNet while it was in the Beta stage. Ewe Beta! Since then I discovered there is more than one way to tackle a start of a project and I have perfected it for my purpose.

    I would suggest starting with an empty project rather than letting Microsoft build you one. By you creating an empty project you are able to control what goes in it. The “Web Forms”template that Microsoft offers has so many files and structure that you would likely not even use.

    If your create a WebForm or Master page, you will likely notice a “FORM” tag with a “runat=server” attribute in it surrounding where you would put your content; this is known as global form. I say get rid of this. It will only frustrate you and/or your designers. Often you will require a form or two on the page for the purpose of “sign-up” or “search” functions and the global form will only hinder that. NUKE the global form.

    Fill your project with everything you may need.

    • Folders (assets, images, scripts)
    • Master Page(s)
    • App_Code Folder
    • Global.asax
    • Web.config

    I would suggest a few simple rules:

    • Avoid Query String – Use Page Routes
    • Avoid ViewState – turn it off in the web.config
    • No more than two Master pages
    • You master page should contain a content place holder at the bottom for scripts
    • Do not use host resources ( scripts, styles ) as you do not have control
    • Avoid DotNet Controls – they carry a lot of baggage

    DotNet controls carry a lot of baggage. ViewState, strange rendering and more often plague or complicate a project by using DotNet controls. PHP, Classic ASP and other platforms can use raw HTML controls and so can you in WebForms. If you need to have C# push data into the controls, add a “runat=server” attribute. If you need to track state, use jQuery and AJAX to write to a session object. I do not find I need to worry about state too often.

    Use page routes instead of QueryString parameters. Routes are less hacked and create a friendly URL. Routes are search engine friendly where QueryString parameters are less friendly. Here is a sample of a Page Route

    http://localhost:55757/Login is really http://localhost:55757/Login.aspx

    http://localhost:55757/SalesReportSummary/01/2014 is similar to http://localhost:55757/salessummary.aspx?month=01&year=2014

    public class Global : System.Web.HttpApplication
    {
            void RegisterRoutes(RouteCollection routes)
            {
                routes.MapPageRoute("", "SalesReportSummary/{month}/{year}", "~/salessummary.aspx");
                routes.MapPageRoute("", "SalesReportSummary", "~/salessummary.aspx");
                routes.MapPageRoute("", "Login", "~/login.aspx");
                routes.MapPageRoute("", "", "~/default.aspx");
                routes.MapPageRoute("", "logout", "~/logout.aspx");
            }
    }
    

    Here is my template for a new project: Project Template

    The post Starting a WebForm Project appeared first on Software Developer In London.

Author:
Categories: Better Coding, C#, C-Sharp, Developement, DotNet, Web, c#, HTML, LdnDeveloper, Web Design


©2017 LdnDeveloper
rolex replica replica watches rolex replica