ASP.NET 4.5 and ASP.NET Core 1 Hosting BLOG

Tutorial and Articles about ASP.NET 4.0 and the latest ASP.NET 4.5 Hosting

ASP.NET Hosting with ASPHostPortal.com :: Working With ASP.Net Web Forms in Visual Studio 2013

clock December 23, 2013 11:56 by author Ben

Here you will create the data models and use the entity classes in it. The Entity Framework is used as a reference to use the entity classes. The Entity Framework is an Object Relational Mapping (ORM) framework. We use it to reduce the data access code that we used to access the data. It provides the entity classes to access the data using LINQ.

 

There are various types of approaches in Entity Framework. We'll use the Code First Approach to define the data models by using classes. We'll map them to an existing database or use it to generate the new database. The Entity Framework reference already exists in the references in the ASP.NET Web Forms Application. You can see that in the screenshot below:

If it is not present then it can be installed from the NuGet Package Manager. You must have a reference to the System.Data.Entity namespace to include the Entity Framework. It enables the classes to query, insert, update and delete the data. To install the Entity namespace, use the following procedure:

Step 1: Right-click on "References" and click on "Add Reference".

We'll create the class to specify the schema of the data and such a class is called an Entity Class. We'll create properties here to designate the fields in our table in the database. Use the following procedure to create the classes.

Step 1: In your Solution Explorer, right-click on the "Models" folder to add a class.

Step 2: Enter the name of the class as "Cricketer".

 

Step 3: Replace the class code with the code given below:

Add the following assembly:

using System.ComponentModel.DataAnnotations;

Code:

public class Cricketer

{

    [ScaffoldColumn(false)]

    public int CricketerID { get; set; }

  

    [Required, StringLength(100), Display (Name="Name")]

    public string CricketerName { get; set; }

  

    [Required, StringLength(50)]

    public string Team { get; set; }

 

    [Required]

    public string Grade { get; set; }

    public int? DetailsID { get; set; }

    public virtual Detail Detail { get; set; }

}

Step 4: Generate another class named Detail.

Add the following assembly:

using System.ComponentModel.DataAnnotations;

Then replace the class code with the following code:

public class Detail

{

    [ScaffoldColumn(false)]

    public int DetailsID { get; set; }

 

    [Required]

    public int ODI { get; set; }

 

    [Required]

    public int Test { get; set; }

    public virtual ICollection<Cricketer> Cricketers { get; set; }

}

Data Annotations

As you'd see above, some of the properties have the attributes designating the restrictions about the member such as [ScaffoldColumn(false)]. These are called data annotations. They specify the details and describe the validations for the user.

Context Class

We need to define the context class to use the classes for data accessing from the table in the database. Use the following procedure to add a context class.

Step 1: Right-click on the "Models" folder to add a new class.

Step 2: Enter the class name as CricketerContext.

Step 3:

Add the following assembly:

using System.Data.Entity;

Then replace the code with the following code:

public class CricketerContext : DbContext

{

    public CricketerContext()

        : base("WebFormsApplication")

    {

    }

 

    public DbSet<Detail> Details { get; set; }

    public DbSet<Cricketer> Cricketers { get; set; }

}


The class defined above represents the Entity Framework cricketer database context and to handle the storing and updating of the Cricketer class instances in the database.

Database Initializer Class

We'll provide some custom logic to initialize the database for running the first time the context is to be used. This will allow adding the seeded data to the database that represents the cricketer and details data.

Step 1: Add another class named CricketerDatabaseInitializer in the models folder.

Step 2:

Add the following assembly:

using System.Data.Entity;

Then modify your code with the following code:

public class CricketerDatabaseInitializer : DropCreateDatabaseIfModelChanges<CricketerContext>

{

    protected override void Seed(CricketerContext context)

    {

        GetDetails().ForEach(d => context.Details.Add(d));

        GetCricketers().ForEach(c => context.Cricketers.Add(c));

    }

 

    private static List<Detail> GetDetails()

    {

        var details = new List<Detail> {

            new Detail

            {

                DetailsID = 1, ODI = 463, Test = 200

            },

            new Detail

            {

                DetailsID = 2, ODI = 311, Test = 113

            },

            new Detail

            {

                DetailsID = 3, ODI = 344, Test = 164

            },

            new Detail

            {

                DetailsID = 4, ODI = 375, Test = 168

            },

        };

 

        return details;

    }

 

    private static List<Cricketer> GetCricketers()

    {

        var cricketers = new List<Cricketer> {

            new Cricketer

            {

                CricketerID = 1, CricketerName = "yourname",

                Team = "India", Grade = "A", DetailsID = 1,

            },

            new Cricketer

            {

                CricketerID = 2, CricketerName = "Saurav Ganguly",

                Team = "India", Grade = "A", DetailsID = 2,

            },

            new Cricketer

            {

                CricketerID = 3, CricketerName = "
yourname",

                Team = "India", Grade = "A", DetailsID = 3,

            },

            new Cricketer

            {

                CricketerID = 4, CricketerName = "
yourname",

                Team = "Australia", Grade = "A", DetailsID = 4,

            },

    };

 

        return cricketers;

    }

}


The seed property is overridden and set after the initialization and creation of the database. The values from the details and cricketers display on the database. If we modify the database by changing the values through the code above, we'll not see the updated values after running the application because the code uses an implementation of the DropCreateDatabaseIfModelChanges class to recognize if the model has changed before resetting the seed data.

Now we have four classes that are created here. For example:

 

Application Configuration

Now, we need to configure the application to use the Model classes. There are two main sections given below:

    Global File Configuration

    Open the Global.asax file.

    Add the following assembly:

    using System.Data.Entity;

    using WebFormsApplication.Models;

    Then modify the code with the following code:

    void Application_Start(object sender, EventArgs e)

    {

        // Code that runs on application startup

        RouteConfig.RegisterRoutes(RouteTable.Routes);

        BundleConfig.RegisterBundles(BundleTable.Bundles);

        Database.SetInitializer(new CricketerDatabaseInitializer());

    }
    


    Web Config File Configuration

    Open the Web.config file and add the following in the connection string:
    

    <add name="WebFormsApplication" connectionString="Data Source=(LocalDb)\v11.0;
         AttachDbFilename=|DataDirectory|\WebFormsApp.mdf;
         Integrated Security=True"

         providerName="System.Data.SqlClient" />



ASP.NET 4.5 Free Trial Hosting - ASPHostPortal.com :: AJAX Control ToolKit DragPanel Tutorial ASP.NET C#

clock October 24, 2013 10:25 by author Ben

Ajax is Asynchronous JavaScript And Xml. Ajax is a group of interrelated web development techniques used on the client-side to create asynchronous web applications. With Ajax, web applications can send the data to, and retrieve the data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page.


Here i am describing how to use the Ajax Control Toolkit in our webpage.

1. Download from Ajax Ajax Control Toolkit site.

2. Extract the downloaded zip file.

3. Add Ajax refrence to you project through the menu bar click on the website and select add reffrence.

4. Go to the Browse tab and select the Ajax dll file and click ok.

5. Now open your webpage and add script manager roomates is present on you in the category of the toolbox and ajax extension.

6. After that open the Ajax Control Toolkit your category and add any webpage with Ajax control, and set its properties ajax control.


The extender DragPanel Easily Allows users to add "draggability" to their controls. The DragPanel targets any ASP.NET Panel and takes an additional parameter that signifies the control to use as the "drag handle". Once initialized, the user can freely drag the panel around the web page using the drag handle.

First add or open a new WebForm to this project and name it DragPanel.aspx

Next we will add a ToolScriptManager.

Now we can drag a PanelControl to the webform, we added some CSS styling to it, we kept it fairly simple, and we also added some text inside the panel.
Here is copy -paste this code on your workspace :



And now you can compile the program and see the result. Literally this DragPanel Control Extender is so easy to use that you will be tempted to use it all the time with all the panels. We hope you understood the AJAX Tutorial posted Today.



Free ASP.NET hosting - ASPHostPortal.com :: ASPHostPortal.com Proudly Announces Free Trial Windows ASP.NET Hosting

clock October 3, 2013 10:11 by author Ben

ASPHostPortal.com is a premier Windows and ASP.NET Web hosting company that specializes in Windows and ASP.NET-based hosting. We proudly announces 7 Day Free Trial Windows and ASP.NET Hosting to all new customers. The intention of this FREE TRIAL service is to give our customers a "feel and touch" of our system. This free trial is offered for the next 7 days and at anytime, our customers can always cancel the service.

The 7 Day Free Trial is available with the following features:

- Unlimited Domains
- 5 GB Disk Space
- 60 GB of Bandwidth
- 2 MS SQL Database
- Unlimited Email Account
- Support ASP.NET 4.5
- Support MVC 4.0
- Support SQL Server 2012
- Free Installations of ASP.NET And PHP Applications

ASPHostPortal.com believes that all customers should be given a free trial before buying into a service and with such approach, customers are confident that the product / service that they choose is not faulty or wrong. Even we provide free trial service for 7 days, we always provide superior 24/7 customer service, 99,9% uptime guarantee on our world class data center. On this free trial service, our customer still can choose from our three different data centre locations, namely Singapore, United States and Amsterdam (The Netherlands)

Anyone is welcome to come and try us before they decide whether or not they want to buy. If the service does not meet your expectations, our customer can simply cancel before the end of the free trial period.

For all the details of packages available visit ASPHostPortal.com

About ASPHostPortal.com:

ASPHostPortal.com is a hosting company that best support in Windows and ASP.NET-based hosting. Services include shared hosting, reseller hosting, and sharepoint hosting, with specialty in ASP.NET, SQL Server, and architecting highly scalable solutions. As a leading small to mid-sized business web hosting provider, ASPHostPortal strive to offer the most technologically advanced hosting solutions available to all customers across the world. Security, reliability, and performance are at the core of hosting operations to ensure each site and/or application hosted is highly secured and performs at optimum level.



Cheap ASP.NET 4.5 Hosting

We’re a company that works differently to most. Value is what we output and help our customers achieve, not how much money we put in the bank. It’s not because we are altruistic. It’s based on an even simpler principle. "Do good things, and good things will come to you".

Success for us is something that is continually experienced, not something that is reached. For us it is all about the experience – more than the journey. Life is a continual experience. We see the Internet as being an incredible amplifier to the experience of life for all of us. It can help humanity come together to explode in knowledge exploration and discussion. It is continual enlightenment of new ideas, experiences, and passions


Author Link


 

Corporate Address (Location)

ASPHostPortal
170 W 56th Street, Suite 121
New York, NY 10019
United States

Tag cloud

Sign in