Friday, April 22, 2011

jQuery Split revisited

Split method split the string into array of substring and return a new array. The basic syntax for split method is,


1
string.split(separator, limit)
It takes 2 parameters,
1. separator - This is optional. It specifies the character to use for splitting the string. If omitted, the entire string will be returned.
2. limit - This is also optional. This will be an integer value that specifies the number of splits to be made.

Let's see some examples.

Example 1:

1
2
var element = 'jQuery By Example Rocks!!';
var arrayOfStrings = element.split();
In this example, I have not used any separator and not defined any element. So the whole string will be returned back to arrayOfStrings variable.

Example 2:
?
1
2
var element = 'jQuery By Example Rocks!!';
var arrayOfStrings = element.split(" ");
In this example, I have passed space as delimiter or separator to split the string. So arrayOfStrings variable will have 4 items.

1
2
3
4
arrayOfStrings[0] = "jQuery"
arrayOfStrings[1] = "By"
arrayOfStrings[2] = "Example"
arrayOfStrings[3] = "Rocks!"
Example 3:

1
2
var element = 'jQuery By Example Rocks!!';
var arrayOfStrings = element.split(" ",3);
In this example, I have passed space as delimiter or separator to split the string and also passed limit as 3. So arrayOfStrings variable will have only 3 items.

1
2
3
arrayOfStrings[0] = "jQuery"
arrayOfStrings[1] = "By"
arrayOfStrings[2] = "Example"
Hope this post provides you enough information about Split method.

Wednesday, April 13, 2011

after logout back button Problem in asp.net

Put This Code in Page load Event Of login Page

Response.Buffer = true;
            Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
            Response.Expires = -1500;
            Response.CacheControl = "no-cache";

Monday, April 11, 2011

Generate Random Numbers

QL Server has a built-in function that generates a random number, the RAND() mathematical function.  The RAND math function returns a random float value from 0 through 1.  It can take an optional seed parameter, which is an integer expression (tinyint, smallint or int) that gives the seed or start value.
To use it, you can simply do a simple SELECT, as follows:
SELECT RAND() AS [RandomNumber]
The result generated by this SELECT statement is as follows (note that your results may be different from the value shown here, hence the name random)
RandomNumber
---------------------
0.34344339282376501
The output of the RAND function will always be a value between 0 and 1.  If you want to generate a random integer number, all you have to do is multiply it by the maximum value you want generated and then get rid of the decimal places.  One way of getting rid of the decimal places is by CASTing it to INT.  Here's an example of generating a random number with a maximum value of 999,999:
SELECT CAST(RAND() * 1000000 AS INT) AS [RandomNumber]
And here's an example result of this SELECT statement:
RandomNumber 
------------ 
163819

The Downside of the RAND Function
One thing to take note with the RAND function is that if the seed parameter is passed to it, the output will always be the same.  This can be seen with the following:
SELECT RAND(1) AS [RandomNumber]
Running this SELECT statement multiple times with 1 as the seed of the RAND function will always yield the same result:
RandomNumber
---------------------
0.71359199321292355
Another thing to take note with the RAND function is that if it is included in a SELECT statement on a table, the value returned for each row will be the same, as can be seen with the following example.
SELECT TOP 10 RAND() AS [RandomNumber], [CustomerID], [CompanyName], [ContactName]
FROM [dbo].[Customers]
RandomNumber         CustomerID CompanyName                         ContactName
-------------------- ---------- ----------------------------------- -------------------
0.21090395019612362  ALFKI      Alfreds Futterkiste                 Maria Anders
0.21090395019612362  ANATR      Ana Trujillo Emparedados y helados  Ana Trujillo
0.21090395019612362  ANTON      Antonio Moreno Taquería             Antonio Moreno
0.21090395019612362  AROUT      Around the Horn                     Thomas Hardy
0.21090395019612362  BERGS      Berglunds snabbköp                  Christina Berglund
0.21090395019612362  BLAUS      Blauer See Delikatessen             Hanna Moos
0.21090395019612362  BLONP      Blondesddsl père et fils            Frédérique Citeaux
0.21090395019612362  BOLID      Bólido Comidas preparadas           Martín Sommer
0.21090395019612362  BONAP      Bon app'                            Laurence Lebihan
0.21090395019612362  BOTTM      Bottom-Dollar Markets               Elizabeth Lincoln

http://www.sql-server-helper.com/tips/generate-random-numbers.aspx

Date and Time Data Types and Functions

9999-12-31
0.00333 second
8
No
No
datetime2
YYYY-MM-DD hh:mm:ss[.nnnnnnn]
0001-01-01 00:00:00.0000000 through 9999-12-31 23:59:59.9999999
100 nanoseconds
6 to 8
Yes
No
datetimeoffset
YYYY-MM-DD hh:mm:ss[.nnnnnnn] [+|-]hh:mm
0001-01-01 00:00:00.0000000 through 9999-12-31 23:59:59.9999999 (in UTC)
100 nanoseconds
8 to 10
Yes
Yes
Note Note
The Transact-SQL rowversion data type is not a date or time data type. timestamp is a deprecated synonym for rowversion.
The Transact-SQL date and time functions are listed in the following tables. For more information about determinism, see Deterministic and Nondeterministic Functions.

Functions That Get System Date and Time Values

All system date and time values are derived from the operating system of the computer on which the instance of SQL Server is running.

Higher-Precision System Date and Time Functions

SQL Server 2008 R2 obtains the date and time values by using the GetSystemTimeAsFileTime() Windows API. The accuracy depends on the computer hardware and version of Windows on which the instance of SQL Server is running. The precision of this API is fixed at 100 nanoseconds. The accuracy can be determined by using the GetSystemTimeAdjustment() Windows API.

Frequently Asked Questions - SQL Server Data Types





Comma-Delimited Output

DECLARE cCustomerIDs CURSOR FOR
    SELECT [CustomerID] FROM [dbo].[Customers] ORDER BY [CustomerID]
DECLARE @CustomerIDs    VARCHAR(8000)
DECLARE @CustomerID     VARCHAR(10)

OPEN cCustomerIDs
FETCH NEXT FROM cCustomerIDs INTO @CustomerID
WHILE @@FETCH_STATUS = 0
BEGIN
    SET @CustomerIDs = ISNULL(@CustomerIDs + ',', '') + @CustomerID
    FETCH NEXT FROM cCustomerIDs INTO @CustomerID
END

CLOSE cCustomerIDs
DEALLOCATE cCustomerIDs

SELECT @CustomerIDs AS CustomerIDs
GO
A sample output of this script is as follows, using just the first 10 Customer IDs from the Customers table.
CustomerIDs
-----------------------------------------------------------
ALFKI,ANATR,ANTON,AROUT,BERGS,BLAUS,BLONP,BOLID,BONAP,BOTTM


http://www.sql-server-helper.com/tips/comma-delimited-output.aspxhttp://www.sql-server-helper.com/tips/comma-delimited-output.aspx

Splash Screen in Silverlight 4

In this post I will show you how to create the custom splash screen for your Silverlight application. You have seen many software which use nice splash screen during loading of the software applications like Microsoft office, excel and many others. I have also created splash screen for my desktop applications which I have developed during my professional life. But I didn’t created any for the web application which I have developed in asp.net. But now the Silverlight provide the functionality of the splash screen. Splash screens provide something interesting and creative to increase anticipation and excitement for the application.
The splash screen is displayed while the .xap file is downloading when the .xap file is downloaded the splash screen disappear. So xaml file for the splash screen is not included in the Silverlight application rather the splash screen file which is of xaml is placed in the web application. When Silverlight application start the default splash screen which you can see is the shown in the image 1. Here you can see the spinning blue balls animation splash screen.

Image 1

Let us start with the our own splash screen , the splash screen which I have created is shown in the Image 2. In Image 2 you can see that I have created simple splash screen for my application which will show the percentage complete in digits so that user can see how much the application is downloaded.
Image 2

The code for the splash screen which is written in the file SilverlightLoader.xaml is place in the web project which you can see after downloading the source code. The code consist of the grid layout and then Border and the textblock which will shown the download complete in percentage. I have also set drop shadow effect for the border which contain the text block control.
The next step is to integrate the custom splash screen with the web application. You can see in the List 1 splashScreenSource property is used to reference the splash screen. By using this property, you can point to where a custom splash screen’s XAML is stored.

<div id="silverlightControlHost"> <object id="SilverlightPlugIn" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <param name="source" value="ClientBin/Custom Splash Screen.xap" /> <param name="onError" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="4.0.50401.0" /> <param name="splashScreenSource" value="SilverlightLoader.xaml" /> <param name="onSourceDownloadProgressChanged" value="appDownloadProgressChanged" /> <param name="autoUpgrade" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration: none"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style: none" /> </a> </object> <iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px; border: 0px"></iframe> </div>
List 1

The next step is to monitor the download progress of the .xap file for this you  need to wire up JavaScript event handlers to the onSourceDownload-ProgressChanged events defined by the plug-in. The definition of the changed event is listed in the List 2 as shown below. The onSourceDownloadProgressChanged event will fire any time the progress of a download has changed by 0.5 percent or more. If this event is triggered, you may access the total progress through the second parameter of the onSourceDownloadProgressChanged event. This parameter exposes a floating-point property called progress. The value of  this property is between 0.0 and 1.0, so you must multiply the value by 100 in order to convert the value to a percentage. When the progress has reached 1.0, the onSource- DownloadComplete event will fire.

function appDownloadProgressChanged(sender, args) { var host = document.getElementById("SilverlightPlugIn"); var percentTextBlock = host.content.findName("PercentageTextBlock"); percentTextBlock.Text = "" + Math.round(args.progress * 100) + "%"; }
List 2

Hope you get idea of how to integrate the custom splash screen with the silverlight application. I have created simple splash screen you can create animations during the download progress.

Note: As I have used the control of silverlight application like border, grid and text block I have added the reference of the PresentationCore and PresentationFramework in my web application.

I have not not included the silverlight application in the source project. As I was testing the output locally so I have embed large image files in the silverlight application so that size of the .xap file will  increase and it will take some time to download locally.