Feb 26th, 2009 | 1 Comment

The GridView control provides you with the option of sorting and paging records without requiring a form-post back to the Web server. In other words, you can re-render the contents of a GridView when sorting and paging, without needing to re-render the entire page.

You enable client paging and sorting by assigning the value true to the EnableSortingAndPagingCallback property. When this property has the value true, the GridView uses JavaScript to request an updated set of records from the Web server.


1 <%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

2

3 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

4 <html>

5 <head id=”Head1″ runat=”server”>

6 <title>Callback GridView</title>

7 </head>

8 <body>

9 <form id=”Form1″ runat=”server”>

10 <%=DateTime.Now %>

11 <asp:GridView ID=”GridView1″ DataSourceID=”TitlesSource” EnableSortingAndPagingCallbacks=”true”

12 AllowPaging=”true” AllowSorting=”true” runat=”Server” />

13 <asp:SqlDataSource ID=”TitlesSource” ConnectionString=”Server=localhost;Database=northwind;Trusted_Connection=true”

14 SelectCommand=”SELECT * FROM customers” runat=”Server” />

15 </form>

16 </body>

17 </html>


Here when you will sort the page or click on the page number the time will not change as it is being set on the page load but the data will get sorted. The time doesn’t change because the page is not reloaded.

Behind the scenes, the GridView uses the Microsoft Internet Explorer XMLHTTPRequest object to communicate with the Web server. This object is supported by Internet Explorer version 5.0 and higher.

However this does not work when you have a templatefield in your Gridview. If you have a templatefield in your Gridview you need to perform the pagination like traditional way handling the events.

Written by Ajay Matharu

February 26th, 2009 at 7:00 pm

Feb 18th, 2009 | No Comments

Many times you need to restrict the number of character’s in multi-line textbox in asp.net. However the maxlength property does not helps in this case what you can do is use this javascript code to restrict the number of input characters in multiline textbox.

<script language=”javascript”>
function textboxMultilineMaxNumber(txt, maxLen) {
try {
if (txt.value.length > (maxLen – 1)) return false;
} catch (e) {
}
}
</script>

use javascript like this,

<asp:textbox id=”TextBox1″ runat=”server” Width=”232px” TextMode=”MultiLine” Height=”48px” style=”Z-INDEX: 104; LEFT: 136px; TOP: 336px”
onkeypress=”return textboxMultilineMaxNumber(this,10)”></asp:textbox>

Written by Ajay Matharu

February 18th, 2009 at 11:03 am