Thursday, April 16, 2009

http://www.javascriptfreecode.com/

Java Script Free Code

Tuesday, April 14, 2009

How to go back to the previous page in ASP.NET 2.0 with C#

// static variable
static string prevPage = String.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if( !IsPostBack )
{
prevPage = Request.UrlReferrer.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect(prevPage);
}
--------------------
protected void Page_Load(object sender, EventArgs e)
{
if( !IsPostBack )
{
ViewState["RefUrl"] = Request.UrlReferrer.ToString();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
object refUrl = ViewState["RefUrl"];
if (refUrl != null)
Response.Redirect((string)refUrl);
}



Wednesday, April 8, 2009

Paging With SQL Server Stored Procedures In ASP.NET

Data paging is very useful when you work with large amount of data. Instead of confusing your user with thousands or maybe even millions of records you simply show only first page with 10, 20 or 30 records and enable navigation buttons like Next or Previous if user wants to see other pages. Standard ASP.NET server controls, like GridView have built in paging capabilities in two modes: simple or custom.

Simple paging is easy to implement but it always bind complete records set which is not so scalable solution and can take a lot of network traffic and work very slow if you have large table or your web site is on shared hosting or especially if you have a lot of concurrent visitors. More about how to implement simple or custom paging in GridView and ListView you can read in Data Paging in ASP.NET tutorial.

But, which ever server control you use for data presentation, to get efficient and scalable data paging you need to do all your paging logic on SQL Server's side and SQL Server should return only selected page to ASP.NET web application. With logic like this, you get faster solution, need less memory and avoid too much traffic between SQL Server and web server. On SQL Server side, you can do paging on two main ways:

1. By building a dynamic SQL query

2. By using a stored procedure

Both methods are used widely, to find out how to build dynamic SQL queries for paging check SQL Queries For Paging In ASP.NET. In this tutorial we will see some common solution when paging is done with stored procedure.


Paging stored procedure with three nested queries

I will publish next time.

Setting the maximum length of a singleline/multiline text box

How can I set the maximum length of a singleline/multiline textbox in a webform?

Restricting the length of text on a Single line/Multi line textbox is not supported by the standard ASP.NET Web control. This can be done by adding the following Javascript function in your ASPX page.

1. Add a javascript:
At the top of your ASPX page you will see the following tag . Add the following code under this tag:

function Count(text,long)
{
var maxlength = new Number(long); // Change number to your max length.
if (text.value.length > maxlength){
text.value = text.value.substring(0,maxlength);
alert(" Only " + long + " characters");
}
}

2. Change your text controls on your ASPX page
On every multi-line text box where you would like to control the length, add the following code to the asp text box control.
onKeyUp="Count(this,300)" onChange="Count(this,300)"

Your original text control before adding this code:
<asp:TextBox ID="TESTDATA" runat="server" TextMode="MultiLine">asp:TextBox>

After adding the code:
<asp:TextBox ID="TextBox1" runat="server" onKeyUp="Count(this,300)" onChange="Count(this,300)" TextMode="MultiLine">asp:TextBox>

Saturday, April 4, 2009

Regular Expressions,.NET, C# Programming

Positive decimal value regular expression with max 3 decimal places:
Regular Expressions, .NET, C# Programming Language
* Accepts all positive decimal values (currently only accepts values greater and equal to one (1))
* i.e accepts ---> 0.0001
* Can have maximum 3 decimal places.
* Decimal places are optional.
This regular expression will be used to validate currency input.
1:ValidationExpression="^\d*[1-9]\d*(\.\d+)?$"

Validate Indian Vehicle Number:
@"^[a-zA-Z]{2}[a-zA-Z0-9]{0,6}[0-9]{3}$"

http://www.cs.princeton.edu/introcs/72regular/