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 4.5.2 Hosting with ASPHostPortal.com :: How to Bind Pages in ASP.NET

clock September 29, 2014 12:31 by author Kenny

How to Bind Pages in ASP.NET

ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web applications with a minimum of coding. ASP.NET is part of the .NET Framework, and when coding ASP.NET applications you have access to classes in the .NET Framework. You can code your applications in any language compatible with the common language runtime (CLR), including Microsoft Visual Basic and C#. These languages enable you to develop ASP.NET applications that benefit from the common language runtime, type safety, inheritance, and so on.

If you are familiar with classic ASP, the declarative data binding syntax introduced in ASP.NET will be familiar to you even though the functionality is vastly different. Data binding expressions are the code you see between <%# and %> characters in an ASPX file. The expressions allow you to easily bind controls to data sources, as well as properties, expressions, and results from method calls exposed by the page. While this feature is easy to use, it often causes some confusion about what is allowed and whether it should be employed.

Data binding basics

Data binding expressions link ASP.NET page properties, server control properties, and data sources when the page's DataBind method is called. You can place data binding expressions on the value side of an attribute/value pair in the opening tag of a server control or anywhere in the page. All data binding expressions, regardless of where you place them, must be contained between <%# and %> characters.

When used with data controls (like Repeater, DataGrid, and so forth), the expression parameter is usually a column name from the data source. However, as long as it returns a value, any valid expression may be used. Likewise, the same syntax may be used outside list controls. This includes displaying values on the page or populating control attributes.

Container.DataItem is a runtime alias for the DataItem bound to a specific item. It maps to an individual item from the data source—like one row from a database query or an individual element from an array. The actual data type for the DataItem is determined by the data source. So, if you're dealing with an array of integers, the DataItem will be an integer.

The following list provides a quick review of the VB.NET syntax for various scenarios:

<%# Container.DataItem %>--An array of string values is returned.
<%# Container.DataItem("expression") %>--The specific field from a DataView container is returned.

<%# Container.DataItem.PropertyName %>--The specific string property value of data source is returned.
<%# CStr(Container.DataItem.PropertyName) %>--Returns a property value converted to its string representation.

When you're using C#, the syntax is a bit different. The following list includes the corresponding C# code for each line in the previous list. Notice the basic syntax is the same, but it changes when property values are returned and converted to the appropriate data type.

<%# Container.DataItem %>
<%# ((DataRowView)Container.DataItem)["PropertyName"] %>
<%# ((ObjectType)Container.DataItem).PropertyName %>
<%# ((ObjectType)Container.DataItem).PropertyName.ToString() %>

Syntax is consistent when working with page level properties and methods. The syntax remains the same as long as string values are returned. The following list provides some examples:

<%# propertyName %>--The value for a page level property is returned.
<asp:ListBox id="lstValues" datasource='<%# propertyName %>' runat="server">--The value retrieved from the page level property (array, collection of objects, etc.) is bound to the data control.

<%# (objectName.PropertyName) %>--The value of the page level object property is displayed.
<%# MethodName() %>--The value returned from the page method is displayed.

You may use individual values (albeit properties, method return values, and so forth) on a page using the following syntax:
<%= Value %>

Using the Contain.DataItem object can be tedious, since you must be aware of the data type and convert it accordingly for use. Microsoft does provide the DataBinder class to further simplify development.

Working with DataBinder

Microsoft documentation (on MSDN) states the DataBinder class uses reflection to parse and evaluate a data binding expression against an object at runtime. This method allows RAD designers, such as Visual Studio .NET, to easily generate and parse data binding syntax. This method can also be used declaratively on a Web form's page to simplify casting from one type to another.

You can use the Eval method of the DataBinder class to make .NET do the heavy lifting when using data values in an ASP.NET page. The Eval method accepts the previously covered Container.DataItem object; it works hard to figure out the details of the field identified in the expression and displays it accordingly. It has the following syntax:

DataBinder.Eval(Container.DataItem, "field name", "optional formatting")

The DataBinder.Eval approach is great as it pushes work to the system. On the other hand, you should use it with caution, since time and resources are consumed as the system locates the element and determines its object/data type.

Plenty of options

Data binding makes it relatively simple to include data in ASP.NET pages. There are various data binding options available, which include: binding the data to a control and allowing it to decide how it is presented, or choosing declarative data binding to control presentation within the ASP.NET page. In the end, it comes down to your preference, but it is great to have options.

Best and Cheap ASP.NET Hosting

Are you looking for best and cheap ASP.NET Hosting? Look no further, ASPHostPortal.com is your ASP.NET hosting home! Start your ASP.NET hosting with only $1.00/month. All of our .NET hosting plan comes with 30 days money back guarantee, so you can try our service with no risk. Why wait longer?



ASP.NET 4.5.2 Hosting with ASPHostPortal :: How to Publish and Deploy an ASP.NET Application in IIS

clock September 16, 2014 12:08 by author Kenny

Simple Way to Publish and Deploy an ASP.NET Application in IIS

ASP.NET is an open source server-side Web application framework designed for Web development to produce dynamic Web pages. It was developed by Microsoft to allow programmers to build dynamic web sites, web applications and web services. While Internet Information Services (IIS, formerly Internet Information Server) is an extensible web server created by Microsoft for use with Windows NT family. IIS supports HTTP, HTTPS, FTP, FTPS, SMTP and NNTP.

In this post, we will describe you how to publish and deploy your ASP.NET application in IIS. Actually it is so simple thing, you can publish your web application to the File System and copy paste all the files to your server. After that, you can add a new website from IIS. If you are not sure what files you should include, it's better to choose 'All files in the project' from the Package/Publish Web. Otherwise choose 'Only files needed to run this application'. You can set this by right clicking on the web application in the solution explorer and choosing 'Package/Publish Settings'.

Right click on your project in the solution explorer and choose 'Publish'. From the dialog box, as the publish method, choose 'File System'. And choose some directory as the Target Location.

You can add the website by right clicking on the 'Sites' in IIS.

Then give a name to your site and select the Physical path from where you copied the site folder

Best and Cheap ASP.NET Hosting

Are you looking for best and cheap ASP.NET Hosting? Look no further, ASPHostPortal.com is your ASP.NET hosting home! Start your ASP.NET hosting with only $1.00/month. All of our .NET hosting plan comes with 30 days money back guarantee, so you can try our service with no risk. Why wait longer?



ASP.NET 4.5.2 Hosting in United Arab Emirates with ASPHostPortal :: How toTransfer Data from One Page to another Page in ASP.NET 4.5.2

clock June 10, 2014 11:47 by author Kenny

ASP.NET is a web programming platform developed by Microsoft. It is the successor to Active Server Pages. The term "classic ASP" is often used to distinguish previous versions of Active Server Pages with the .NET (pronounced "dot net") versions. How many ways do you know to send the data between ASP.NET Pages? In this post I’m going to list 8 different ways.

Now, let me explain how to learn multiple ways to transfer data from one ASP.NET page to another. Some of these include using the cache, http posts, querystring variables, ASP.NET session state, etc. Each button in the demo has the required code in it's Click event handler, and brings you to a separate target page that gets and displays the data that was sent. Let’s check here are the methods:

1. Use the querystring:
The QueryString collection is used to retrieve the variable values in the HTTP query string.  Using this technique I will add my data with URL and on the next page will grab it.

 protected void QueryStringButton_Click(object sender, EventArgs e)
          {
              Response.Redirect("QueryStringPage.aspx?Data=" + Server.UrlEncode(DataToSendTextBox.Text));
         }


2. Use HTTP POST:
The Hypertext Transfer Protocol (HTTP) is a communication protocol that is designed to enable request-response between clients and servers.  Using this technique I will call a post back url and the on next page using Request.From I will grab it.

 <asp:Button ID="HttpPostButton" runat="server" Text="Use HttpPost" 
              PostBackUrl="~/HttpPostPage.aspx" onclick="HttpPostButton_Click"/>
 
 protected void HttpPostButton_Click(object sender, EventArgs e)
         {
      // The PostBackUrl property of the Button takes care of where to send it!
         }


3. Use Session State:
Sessions can be used to store even complex data for the user just like cookies. Actually, sessions will use cookies to store the data, unless you explicitly tell it not to. Sessions can be used easily in ASP.NET with the Session object. Using this technique I will store the data in session variable on the client machine and on the next page will grab it. Using Application Variable instead of Session Variable is recommended by experts.

    protected void SessionStateButton_Click(object sender, EventArgs e)
          {
              Session["Data"] = DataToSendTextBox.Text;
              Response.Redirect("SessionStatePage.aspx");
         }


4.  Use public properties:
Properties are not just to provide access to the fields; rather, they are supposed to provide controlled access to the fields of our class. Using this technique I will send the using a public method and on the next page will grab it using PreviousPage.MethodName.

    public string DataToSend
         {
             get
             {
                  return DataToSendTextBox.Text;
              }
         }
 
         protected void PublicPropertiesButton_Click(object sender, EventArgs e)
          {
              Server.Transfer("PublicPropertiesPage.aspx");
         }


5. Use PreviousPage Control Info:
Using this technique I will just redirect the user on next page and on the next page will use PreviousPage.FindControl to grab the data.

 protected void ControlInfoButton_Click(object sender, EventArgs e)
          {
              Server.Transfer("ControlInfoPage.aspx");
         }
 
   // target page:
 protected void Page_Load(object sender, EventArgs e)
         {
             var textbox = PreviousPage.FindControl("DataToSendTextbox") as TextBox;
              if (textbox != null)
             {
                 DataReceivedLabel.Text = textbox.Text;
             }
         }


6. Use HttpContext Items Collection:

   protected void HttpContextButton_Click(object sender, EventArgs e)
          {
              HttpContext.Current.Items["data"] = DataToSendTextBox.Text;
              Server.Transfer("HttpContextItemsPage.aspx");
         }
 
 // target page:
 protected void Page_Load(object sender, EventArgs e)
          {
              this.DataReceivedLabel.Text =(String) HttpContext.Current.Items["data"];
         }


7. Use Cookies:
Cookies are small pieces of text that are passed between browser and web server with every request. As a consequence, their values are available to any page within the site. Cookies are commonly used to store user preferences which help the site remember which features to turn on or off, for example. They might be used to record the fact that the current user has authenticated and is allowed to access restricted areas of the site. It is the browser's job to store persistent cookies as text files on the client machine. The storage duration is determined by the type of cookie and the expiry date that it is given. Cookies with no expiry date are not stored on the client machine and are cleared at the end of the user's session.

 protected void CookiesButton_Click(object sender, EventArgs e)
         {
             HttpCookie cook =  new HttpCookie("data");
             cook.Expires = DateTime.Now.AddDays(1);
             cook.Value = DataToSendTextBox.Text;
              Response.Cookies.Add(cook);
              Response.Redirect("HttpCookiePage.aspx");
         }
 
 // target page:
 protected void Page_Load(object sender, EventArgs e)
         {
             DataReceivedLabel.Text = Request.Cookies["data"].Value;
         }


8. Use Cache:
The Cache is primarily intended to be used to improve performance of web pages, in that you can add any arbitrary object to it and retrieve it at will. Cache items are stored in memory on the server, and can be considered as special global variables. In fact, pre-ASP.NET, Application state used to be treated as a kind of cache. The difference between Application variables and Cache is that Cache offers a management API. In Web Pages, cache is managed via a WebCache helper. When you want to add something to the Cache, you use the WebCache.Set method. This method takes four parameters: the name you want to give the cache item, the item itself, the number of minutes that the item should remain in the Cache (default: 20) and whether those minutes should restart everytime the item is referenced or not (default: true). This is called Sliding Expiration.

 protected void CacheButton_Click(object sender, EventArgs e)
          {
              Cache["data"] = DataToSendTextBox.Text;
              Server.Transfer("CachePage.aspx");
         }
    // target page:
     protected void Page_Load(object sender, EventArgs e)
          {
              this.DataReceivedLabel.Text = (string) Cache["data"];
         }


ASP.NET 4.5.2 Hosting with ASPHostPortal.com :: New Features of ASP.NET 4.5.2 - Event Tracing Changes

clock June 5, 2014 06:36 by author Kenny

ASP.NET 4.5.2 is the latest ASP.NET version; it is a highly compatible, in-place update to the .NET Framework 4, 4.5 and 4.5.1. The new ASP.NET 4.5.2 some new features that very useful for ASP.NET developer. What's new in this release of .NET 4.5.2 Framework?

  • New APIs for ASP.NET apps;
  • Resizing in Windows Forms controls;
  • New workflow features;
  • Profiling improvements;
  • Debugging improvements;
  • Event tracing changes.

Well, now I will be talking about one of them. It is about “Event tracing”. As you know that Event Tracing for Windows or ETW is an efficient kernel-level tracing facility that lets you log kernel or application-defined events to a log file. It makes you can consume the events in real time or from a log file and use them to debug an application or to determine where performance issues are occurring in the application.

And not only that, ETW has more function again. ETW lets you enable or disable event tracing dynamically, allowing you to perform detailed tracing in a production environment without requiring computer or application restarts. Use ETW when you want to instrument your application, log user or kernel events to a log file, and consume events from a log file or in real time.

In the new ASP.NET 4.5.2 Event Tracing has great change. The new .NET Framework 4.5.2 enables out-of-process, Event Tracing for Windows based activity tracing for a larger surface area. Not only that, this enables Advanced Power Management (APM) vendors to provide lightweight tools that accurately track the costs of individual requests and activities that cross threads. These events are raised only when ETW controllers enable them; therefore, the changes don’t affect previously written ETW code or code that runs with ETW disabled.

Are you interest with other new features in ASP.NET 4.5.2? So just stay tune in this blog. We will always give you up to date news about ASP.NET.



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