Friday, 16 December 2011

What is JSON ?

JSON stands for JavaScript Object Notation that is a language independent text format which is fast and easy to understand.On the server-side you can easily serialize/deserialize your objects to/from JSON.JSON (Java Script Object Notation) provides a simple data format for the exchange of information between the browser and server. In other words JSON is light weight data-interchange format.
An object described in JSON consists of a set of curly braces {} enclosing a set of attribute-value pairs.
For example:
{"movielist": ["Friday the 13th", "Friday the 13th Part 2", "Friday the 13th Part III", "Friday the 13th: The Final Chapter", "Friday the 13th: A New Beginning"]}

Thursday, 15 December 2011

Bulk insert excel to sql ?

sp_configure 'show advanced options' , 1
RECONFIGURE;
Go
sp_configure 'Ad Hoc Distributed Queries' , 1
RECONFIGURE;
GO

SELECT * INTO ItemTemp FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=D:\StudentDetails.xls', [Sheet1$])

Monday, 12 December 2011

How to access ServerSide method from GridView's ItemTemplate

While working with GridView, there may be a case where 
we actually need to do some operations in serverside for 
which we may be in a need to call a server side
method from ItemTemplate of a GridView.

Say for example, 
I had a situation where i need to call a server side 
method (which return a string value) from ItemTemplate.
So i used a label in the ItemTemplate like 


<asp:TemplateField HeaderText="Testing">
<ItemTemplate>
<asp:Label ID="lblCustomerAge" Text='<%# GetCategory() %>' runat="server">
</asp:Label>
</ItemTemplate>
</asp:TemplateField>

Here GetCategory is the server side method.Code-behind is given below

  protected string GetCategory()
    {
       // Do whatever you want here
        return "TestCategory"; // For eg. passing a string
    }

How to open a pop up window with specified location through Javascript

Below is the javascript method that opens a popup with specific height,width,location etc

function openQuadPopup(val) {           
            var width = screen.width - 100;
            var height = screen.height - 100;
            var leftPos = (screen.width - width - 30) / 2;
            var topPos = (screen.height - height - 30) / 2;
            myWindow = window.open('TestPage.aspx?QueryStringValue=' + val, 'NameForPopup', 'menubar=0,resizable=0,width=' + width + ',height=' + height + "'");

            myWindow.moveTo(leftPos, topPos);          
        }

Sunday, 20 November 2011

Difference between Session object and Application object in asp.Net

Session variables are used to store user specific information where as in application variables we can't store user specific information.

Default lifetime of the session variable is 20 mins and based on the requirement we can change it.Application variables are accessible till the application ends.

sessions allows information to be stored in one page and accessed in another,and it supports any type of object, including your own custom data types. Application state allows you to store global objects that can be accessed by any client.

The common thing between session and application is both support the same type of objects,retain information on the server, and uses the same dictionary -based syntax.

Tuesday, 15 November 2011

What methods are fired during the page load?

Init() - when the page is instantiated
Load() - when the page is loaded into server memory
PreRender() - the brief moment before the page is displayed to the user as HTML
Unload() - when page finishes loading.

difference between Inline and Codebehind code in asp.net ?

Inline Code is mixing client and serverside code on the same page like HTML and JavaScript. So precompilation is no need.
CodeBehind .aspx separately only for serverside code. So it provides good performance than inline code. Why because CodeBehind needs to be compile in advance.