// build SEO friendly Meta tag Title, Keywords, Descriptions in ASP.? NET Websiteprotectedvoid
Page_Load(object sender, EventArgs e) {if (!Page.IsPostBack) {Page.Title = “SEO Expert India,SEO Services India,SEO Company India,SEO Professional India,India SEO Firms,SEO Experts in UK,SEO Experts in USA”;
HtmlMeta metaTag = newHtmlMeta();
metaTag.Name = “keywords”;metaTag.Content = “search engine optimization,website marketing, search engine optimization company, search engine ranking, search engine optimization services, seo services, search engine positioning services, seo, seo company, search engine placement company, web site promotion”;base.Master.Page.Header.Controls.Add(metaTag);
Difference between properties and get/set method in .net
Properties
Properties represent data.
Properties can easily ? for using the XML serializer
Properties should behave as if they are fields
Retrieving a field’s value does not produce any side effects.
Method
Methods perform actions
Method can’t easily ? use the XML Serialise using get / set methis
The method performs a time-consuming operation. The method is perceivably slower than the time it takes to set or get a field’s value.
The method performs a conversion. Accessing a field does not return a converted version of the data it stores.
The “Get” method has an observable side effect
Calling the method twice in succession creates different results.
The method is static but returns an object that can be changed by the caller. Retrieving a field’s value does not allow the caller to change the data stored by the field.
Indicates the maximum file upload size supported by ASP.NET. This limit can be used to prevent denial of service attacks caused by users posting large files to the server. The size specified is in kilobytes. The default is 4096 KB (4 MB).
In previous columns, I covered the basics of using the .NET 3.5 ListView control and explained how to pair it with the DataPager control. Now I’ll show you how to use these controls with a SQL Server 2005 backend to implement custom paging, in which only a subset of the data is retrieved for display.
When is data loaded?
The default behavior of .NET data components such as ListView and GridView involves retrieving the entire results of a query when loading data for display on a page. A better approach involves loading only data that will display on the page. When a user advances to another page of data, it is loaded from the backend data source and displayed.
This approach introduces more roundtrips between the application and the database, but it is a small price to pay for avoiding the resource intensive chore of loading an entire data set for each page of data. Note: This approach is only more efficient for large data sets.
Subsets via SQL Server 2005
There are various techniques for handling this issue, but SQL Server 2005 introduced a new feature that changed everything. SQL Server 2005 simplifies retrieving subsets of a data source via the T-SQL row_number function.
This function allows you to return a subset of query results. The partition and order by clauses of the row_number function provide what you need. Partitioning is achieved with the over clause, which determines the partitioning and ordering of the intermediary result set before the row_number function is applied.
The results of applying the row_number function is enclosed in a subquery that returns? a temporary named result set. The data you need is picked from this temporary result set. To demonstrate, I use a simple database called Test that has a People table, which is created with the following T-SQL:
The next T-SQL snippet returns a set of five records from the People table using the row_number function. The temporary table is named PeopleRecords within the subquery. The row_number function numbers the rows in the subquery according to the ORDER BY clause. The outer or main query selects the records it needs via a WHERE clause applied to the subquery.
SELECT people_id, lastname, firstname, rownum FROM ( SELECT people_id, lastname, firstname, row_number() over(order by lastname) AS [rownum] FROM Test.dbo.People ) AS PeopleRecords WHERE rownum between 3 AND 7
Five records are returned because the starting record number (3) and ending number (7) are included in the result set. The rows are numbered by their location in the ORDER BY clause in the subquery that orders the records by last name. An ASP.NET application can use this SQL Server 2005 feature to efficiently page through large data sets.
Using the row_number function in ASP.NET
You can combine the new support for retrieving data via their row numbers within a result set with the ListView and DataPager controls to allow users to page through data on a Web page without reading the entire result set for the loading of every new page.
A SQL Server 2005 stored procedure is created to implement this functionality. The stored procedure accepts two parameters: the row number to return and the size of the result set. The source for the stored procedure follows:
CREATE PROCEDURE [dbo].[GetPage] ( @row int, @totalrows int ) AS BEGIN SELECT people_id, lastname, firstname, contactnumber, rownum FROM ( SELECT people_id, lastname, firstname, contactnumber, row_number() over(order by lastname) AS [rownum] FROM Test.dbo.People ) AS PeopleRecords WHERE rownum between ((@row - 1) * @totalrows + 1) AND (@row * @totalrows) END
With the stored procedure created, the ASP.NET Web Form is created to use it. The page contains a ListView control that displays these data fields: id value, first name, last name, and contact number.
A DataPager control is added to the page to allow users to page through the data. This instance of the DataPager control uses a custom template to build the paging interface. The template contains two buttons: Previous and Next. These buttons allow the user to page through the data one set of records at a time.
The two buttons in the DataPager control are tied to the PagerCommand method in the codebehind class file for the page. The method is wired to the DataPager control via its OnPagerCommand attribute.
A ViewState variable is used to keep track of the current page being viewed. This variable is incremented by one when the Next button is selected and decremented by one when the Previous button is clicked.
The codebehind file includes a method called GetData, which is where the call to the stored procedure is made. The GetData method is called by the code for the Next and Previous buttons. The page number and size of the page are passed to the GetData method and passed to the stored procedure via parameters.
The results of calling the stored procedure are placed in a DataSet object that is used as the data source for the ListView control. Here is the code for the Web Form and the codebehind class:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; namespace TechRepublic { public partial class DynamicPaging : System.Web.UI.Page { private readonly String connString = "Data Source=TestSrv;Initial Catalog=Test;User ID=Test;Password=Test"; private SqlConnection conn = null; private SqlCommand comm = null; private SqlDataAdapter sda = null; private DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ViewState["currentrow"] = 1; ListView1.DataSource = GetPage(1, 2); ListView1.DataBind(); } } protected DataSet GetPage(int rowindex, int pagesize) { try { ds.Dispose(); conn = new SqlConnection(connString); conn.Open(); comm = new SqlCommand("GetPage", conn); comm.CommandType = CommandType.StoredProcedure; comm.Parameters.AddWithValue("@totalrows", pagesize); comm.Parameters.AddWithValue("@row", rowindex); sda = new SqlDataAdapter(comm); sda.Fill(ds); return ds; } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } comm.Dispose(); conn.Dispose(); } } protected void PagerCommand(object sender, DataPagerCommandEventArgs e) { int newIndex; switch (e.CommandName) { case "Next": newIndex = (int)ViewState["currentrow"] + 1; ListView1.DataSource = GetPage(newIndex, 2); ListView1.DataBind(); ViewState["currentrow"] = newIndex; break; case "Previous": newIndex = (int)ViewState["currentrow"] - 1; if (newIndex < 1) newIndex = 1; ViewState["currentrow"] = newIndex; ListView1.DataSource = GetPage(newIndex, 2); ListView1.DataBind(); break; default: break; } } } }
You can extend this example in various ways, such as providing a text box for the user to select the page size to be displayed or allowing users to skip to first and last records.
While this is a simple example, it gives you an idea of the options available with the ROW_COUNT function. The function provides a straightforward way to increase page response time by reducing the amount of data that is fetched and displayed.
ASP.NET has a new architecture for detecting and rendering content to mobile devices, and this control architecture has also been implemented by the master page processing, enabling different master pages to be used for different devices. For example, it would be possible to supply different master pages for Internet Explorer and Mozilla. This is achieved by creating separate master pages and then in the page prefixing the master attribute with the name of the device, as shown below:
When this page is accessed by a Mozilla browser, mozilla.master is used. All other browsers use the default master page.? ? where the content simply differs for each browser. Where this comes into its own is in supporting multiple devices, such as small-screen devices, where your master page might need to be very different, perhaps to incorporate a different menu structure.
This article introduces a methodology, Ajax, you can use to build more dynamic and responsive Web applications. The key lies in the combination of browser-side JavaScript, DHTML, and asynchronous communication with the server. This article also demonstrates just how easy it is to start using this approach, by leveraging an Ajax framework (DWR) to construct an application that communicates with backend services directly from the browser. If used properly, this tremendous power allows your application to be more natural and responsive to your users, thereby providing an improved browsing experience.
The sample code used in this application is available for download as a standalone WAR file.
Introduction
The term Ajax is used to describe a set of technologies that allow browsers to provide users with a more natural browsing experience. Before Ajax, Web sites forced their users into the submit/wait/redisplay paradigm, where the users’ actions were always synchronized with the server’s “think time.” Ajax provides the ability to communicate with the server asynchronously, thereby freeing the user experience from the request/response cycle. With Ajax, when a user clicks a button, you can use JavaScript and DHTML to immediately update the UI, and spawn an asynchronous request to the server to perform an update or query a database. When the request returns, you can then use JavaScript and CSS to update your UI accordingly without refreshing the entire page. Most importantly, users don’t even know your code is communicating with the server: the Web site feels like it’s instantly responding.
While the infrastructure needed by Ajax has been available for a while, it is only recently that the true power of asynchronous requests has been leveraged. The ability to have an extremely responsive Web site is exciting as it finally allows developers and designers to create “desktop-like” usability with the standard HTML/CSS/JavaScript stack.
Traditionally in J2EE, developers have been so focused on developing the service and persistence layers that the usability of the user interface has lagged behind. It is common to hear phases such as, “we don’t have time to invest in the UI” or “you can’t do that with HTML” during a typical J2EE development cycle. The following Web sites prove that these excuses don’t hold water any longer:
All these Web sites show that Web applications don’t need to rely solely on pages being reloaded from the server to present changes to the user. Everything seems to happen almost instantly. In short, when it comes to designing a responsive user interface, the bar has now been set much higher.
Defining Ajax
Jesse James Garrett at Adaptive Path defined Ajax as follows:
Ajax isn’t a technology. It’s really several technologies, each flourishing in its own right, coming together in powerful new ways. Ajax incorporates:
Standards-based presentation using XHTML and CSS
Dynamic display and interaction using the Document Object Model
Asynchronous server communication using XMLHttpRequest
JavaScript binding everything together
This is all fine and dandy, but why the name Ajax? Well, the term Ajax was coined by Jesse James Garrett, and as he puts it, it is “short-hand for Asynchronous JavaScript + XML.”
How Does Ajax Work?
The kernel of Ajax is the XmlHttpRequest JavaScript object. This JavaScript object was originally introduced in Internet Explorer 5, and it is the enabling technology that allows asynchronous requests. In short, XmlHttpRequest lets you use JavaScript to make a request to the server and process the response without blocking the user.
By performing screen updates on the client, you have a great amount of flexibility when it comes to creating your Web site. Here are some ideas for what you can accomplish with Ajax:
Dynamically update the totals on your shopping cart without forcing the user to click Update and wait for the server to resend the entire page.
Increase site performance by reducing the amount of data downloaded from the server. For example, on Amazon’s shopping cart page, when I update the quantity of an item in my basket, the entire page is reloaded, which forces 32K of data to be downloaded. If you use Ajax to calculate the new total, the server can respond with just the new total value, thereby reducing the required bandwidth 100 fold.
Eliminate page refreshes every time there is user input. For example, if the user clicks Next on a paginated list, Ajax allows you to just refresh the list with the server data, instead of redrawing the entire page.
Edit table data directly in place, without requiring the user to navigate to a new page to edit the data. With Ajax, when the user clicks Edit, you can redraw the static table into a table with editable contents. Once the user clicks Done, you can spawn an Ajax request to update the server, and redraw the table to have static, display-only data.