HOW TO USE CURSOR

DECLARE @VariableNames DATATYPE
DECLARE @CursorName CURSOR
SET @CursorName= CURSOR FOR datasource

OPEN @CursorName

FETCH NEXT  FROM @CursorName INTO @VariableNames
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT  ‘Do Something
FETCH NEXT FROM  @CursorName INTO @VaribaleNames
END

CLOSE  @CursorName
DEALLOCATE @CursorName

baseJS

i just gone through baseJS API documentation,i found very useful template method and properties.I think they are not in Jquery framework

Example from : http://paularmstrongdesigns.com/projects/basejs/docs/#newtemplate

var myTemplate = new Template(‘#{name} is #{age} years old.’);

var person1 = { name: ‘Jimmy’, age: ’22’ };
var person2 = { name: ‘Janey’, age: ’23’ };

Output
……………………………………………………………………………………
myTemplate.parse(person1); // returns → ‘Jimmy is 22 years old.’
myTemplate.parse(person2); // returns → ‘Janey is 23 years old.

Ref:http://www.greepit.com/2010/07/mobile-javascript-framework-basejs/?goback=.gde_1778847_member_24607596

Beauty of JQuery

by using this concept,we can  access client side ID of server controls easily,hence it will reduce lot of variable declarationin JS. (more..)

AHAH by using JQuery

AHAH stands for Asynchronous HTML and HTTP, as name includes asynchronous, it means we can load html markup without User Experience (UX) interrupt over HTTP.

In common practice, if we want show, some type of summary or details on different pages, we copy past the same html markup on pages. Hence there is no reuse of html markup.

Now come to JQuery, if we required partial or whole html page, we can do by using load command i.e. load (URL, callback) of JQuery.

You can download JQuery from here.

Let’s we have an example as listing below:

STEP 1 Create website project, add JQuery JavaScript file

Project

STEP 2 Add HTMLPage.htm and tow div container as given below:

Div

STEP 3

a. Add default.aspx page and JQuery script reference in default page

b. Insert two div containers in default.aspx page

html

c. Write JavaScript in default.aspx page

<script language=”javascript” type=”text/javascript”>

$(document).ready(function() {

$(‘#aBoth’).click(function() {

//load whole HTMLpage.htm

$(‘#divContainer’).load(‘HTMLPage.htm’, function() { });

});

$(‘#aContainer-1’).click(function() {

//load divContainer-1′ div Container-1 from  HTMLpage.htm only

$(‘#divContainer’).load(‘HTMLPage.htm #divContainer-1’, function() { });

});

$(‘#aContainer-2’).click(function() {

//load divContainer-2′ div Container-2 from  HTMLpage.htm only

$(‘#divContainer’).load(‘HTMLPage.htm #divContainer-2’, function() { });

});

}

);

</script>

// Test: Browse default.aspx page

a. Click on “Both Containers” both

b. Click on “Container-1” c1

c. Click on “Container-2”

c2

If you have questions related to this blog just write your thoughts.

Thanks for reading!

Rukhsar Ahmad

JQuery and $() Backbone of JQuery

 

Introduction
we should say thanks to John Resig and his highly talented team for creating Jquery Framework. After jquery framework, web developer and designer life became easier. Jquery can help you to make your website interactive, attention-grabbing and stimulating. This blog will include different aspect related to jquery.

Web User interface

As per my understanding, I have divided UI into three parts; these are documented structure markup (i.e. HTML markup), stylistic markup (i.e. css) and HTML Component behavior, as shown in below image:

 UI

HTML Markup: This markup includes html controls without any cascading style sheet (i.e. CSS)

Stylistic Markup: This markup includes html controls and CSS classes applied to html controls.

HTML Component Behavior: HTML control is known as html component also. Component behavior, I mean control Animation, Show/Hide and Appearance change on user action etc. here we need Jquery to implement above effect with min line of JavaScript code. 

Generally, whenever we browse any good and interactive site, feel wow! And curious about how they implement wow effect. Then we go for view source of html to understand JavaScript code.

It is very difficult to implement wow! Effect by using raw JavaScript, Don’t worry now we have jquery framework. Jquery is simple JavaScript based framework which has common useful JavaScript function.

Why JQuery?
I am using JQuery from last 3-4 month as per my experience. JQuery is easy to understand hence small learning curve and Cross-browser support so there is no need to worry about cross browser issue before JQuery Framework. In the future JQuery will be the part of ASP.NET so why not we should use this now. In jquery you can write your own plug-in as per you requirement.

no library is full filling all the requirements so does JQuery, so there should be some mechanism to add sets of useful methods called as plug-ins for your specific requirement, which we can say in the basic terminology calling your external methods into your structure but it doesn’t give you the power of leverage existing code base. . JQuery is designed to change the way that you write JavaScript.

 

Unobtrusive DOM Scripting

DOM scripting is nothing but just accessing DOM element by using JavaScript. If you do script in such a way that if user browser does not support JavaScript, page still should be display without any error. That JavaScript is known as Unobtrusive DOM Scripting.

$() Backbone of Jquery

$() is an alias of JQuery and also known as selector. $() can do following things:

  1. DOM component manipulation
  2. DOM component creation
  3. Animation and other effects
  4. Helping in Extending JQuery framework by writing plug-in.

There are few example of selector:

  1. $(“p a”) àreturns the group of links nested in <p> element.
  2. $(“p: even”) àthis selector selects all even <p> elements.
  3. $(“tr: nth-child (1)”) à this selector selects first row of each table.
  4. $(“body > div”) à this selector selects direct <div > children of <body>.

Beware

  1. use JQuery document handler for any JQuery practice i.e. $(document).ready( function() {});
  2. Don’t put many html control id in single selector like

$(“div [id=”divid1”] div [id=”divid2”])   div [id=”divid3”])”), it gives slow response for DOM manipulation

  1. In case of “for loop” don’t do like this for (var j=0; j<$(“a”).length, j++) {} because every time selector will be execute to calculate length again slow response.

 

 

References

1. You can find some JQuery help controls in the below links:

http://www.west-wind.com/tools/westwindajaxtoolkit/docs/?page=_2hh0s4zli.htm

2. Also you can find more documents and help in:

http://www.JQuery.com

3. Nice example on all JQuery methods in XML format:

http://jquery.com/api/data/jquery-docs-xml.xml

4. JQuery with .NET

http://weblogs.asp.net/bleroy/archive/2008/09/28/jquery-now-officially-part-of-the-netdeveloper-s-toolbox.aspx

5. JQuery intellisense in VS.NET 2008:

http://blogs.ipona.com/james/archive/2008/02/15/JQuery-IntelliSense-in-Visual-Studio-2008.aspx

6. Integrating Sharpoint and JQuery:

http://weblogs.asp.net/jan/archive/2008/11/20/sharepoint-2007-and-jquery-1.aspx

7. You can download JQuery from:

http://docs.jquery.com/Downloading_jQuery

8. JQuery Support

http://www.liferay.com/web/guest/services/support/jquery

http://www.cmswatch.com/Trends/1380-Microsoft-to-support-jQuery-24/7

9. JQuery Cheat Sheet

http://www.javascripttoolbox.com/jquery/cheatsheet/

10. Comparasion with other JavaScript framework

http://blog.creonfx.com/javascript/mootools-vs-jquery-vs-prototype-vs-yui-vs-dojo-comparison-revised

 11. Selectors Level 3

http://www.w3.org/TR/css3-selectors/

If you have questions related to this blog just write your thoughts.

Thanks for reading!

Rukhsar Ahmad

Interface Programming

 

According to the basic principle of object-oriented, classes should have not close knowledge of each other. If you are not using interface programming, classes defiantly somehow relates to each other. If you change in one class, it will affect in other classes also so you have recompile whole code.

What is interface?

Interface is a contract between class and outside of the world. As I said contract, it means if class have a contract then class must be implement all contracts of interface. If the class does not, it has broken the contract and compiler will complain and refuse to compile the code.

Declaring the Interface

[Attributes] [Modifier] Interface identifier [: base-list]

{Interface-body}

Attributes–>The attributes section is optional and attributes can contains any declarative information

Modifiers–>the modifier section is optional. The available modifiers are new, public, protected, internal       and internal protected.

Interface–>interface is used to tell the compiler that this is an interface.

Identifier–>this is the place to put name of interface.

: Base-list–>this is place to put the name of other interface. This is optional also.

{Interface-body}–> this section is used to put the methods, properties, indexer and event associated with contract.

 Interface

 Explicit and Implicit Interface Implementations

Implicit–> in case of explicit, user can be access contract by object in which contract is implemented. If two interface have same method, then you cannot implement in one class, hence code would not be compiled.

Example:

Public interface ISpeak

{

           Void Speak ();

}

Public class Dog: ISpeak

{

Public void  Speak ()

{

}

}

Hence you can use above contract like this:

ISpeak objISpeak=new Dog ();

objISpeak. Speak ();

OR

Dog objDog =new Dog (); //so what is the use of interface here

objDog. Speak ();

 

 

Explicit–> in case of implicit, the calling way of method here is different, you can see in example. You can implement same method, are in different interface. In explicit you must omit the access modifier otherwise code will not be compiled. Because access modifier is omitted, you cannot access method from class. You have to use interface.

Example:

Public interface ISpeak1

{

           Void Speak ();

}

Public interface ISpeak2

{

           Void Speak ();

}

 

Public class Dog: ISpeak1, ISpeak2

{

Void ISpeak1. Speak ()

{

//let says this is first contract.

}

Void ISpeak2. Speak ()

{

//this is second contract.

}

 

}

Hence you can use above contract like this:

ISpeak1 objISpeak1=new Dog ();

objISpeak1. Speak (); //first contract will be called.

ISpeak2 objISpeak2=new Dog ();

objISpeak2. Speak (); //second contract will be called.

Mapping the interface

By using this technique, you can decide which method has to use. Let’s have an example:

Namespace mappingtheinterface

{

Interface IDoSomething

{

Void DoSomething ();

}

Class work1: IDoSomething

{

Public void DoSomething ()

{

//let says first method1.

//Implicit implementation

}

}

Class work2:work1,IDoSomething

{

void IDoSomething .DoSomething()

{

//let says first method2.

//this is explicit implementation

}

 

}

Public new void DoSomething ()

{

//let says first method3.

//this is called shadowing, because you are hide method of base class

}

 

}

 

 

Now let’s call method like given below:

Work2 objwork2=new work2 (); //create object of class work2

Objwork2.DoSomething (); //method3 will be called

((IDoSomething) Objwork2).DoSomething (); //method2 will be called, here object is cast o interface

((work1) Objwork2).DoSomething (); //method1 will be called, here object is cast o work1 class

 

Empty Interface?

Empty interface means, nothing in contract, then this is violation of contract. Because if you have contract, have something in contract. The beauty of empty interface, you can use this as marker or you can check data type at code compile time. Let’s we have an example:

[Serializable] //attribute

Public Interface ISerialize

{

}

And above interface implemented to class

Public class Test: ISerialize

{

}

ISerialize interface is used as marker, class is Serializable.

 

If you have questions related to this blog just write your thoughts.

Thanks for reading!

Rukhsar Ahmad

Difference between W3C Box and Internet Explore Model?

 

 

The box model determines how the size of content of element is determined in conjunction with its padding and border. Most browsers other then Internet Explorer (IE) support W3C Box Model, Whereas IE can use either model depending upon whether the page is being rendered in strict mode or quirks mode. Which mode is used depends upon the DOCTYPE.

  1. Pages with a valid and recognized DOCTYPE declaration are rendered in strict mode.
  2. Pages lacking a DOCTYPE declaration or those containing an unrecognized are rendered in quirks mode.

Let’s have an element with following applied style:

{

Width: 180px;

Height: 72px;

Padding: 10px;

Border-width: 5px;

}

 

The box will be display in different model as shoe in below diagram:

 box models

Hence width and height of box models will be as :

 

Model Name Width Height
W3C Box Model  (180+2*10+2*5)px=  210px (72+2*10+2*5)px=102px
Internet Explore box model  (150+2*10+2*5)px=  180px (42+2*10+2*5)px=72px

 

 

If you have questions related to this blog just write your thoughts.

 

Quirks mode and strict mode:

http://www.quirksmode.org/css/quirksmode.html

Thanks for reading!

Rukhsar Ahmad

 

Sharing Business entity between Client (JavaScript) and Web Server by Using ASP.NET AJAX Web Service

 In the new era of Web 2.0, it is very important to update content in client browser, without page refresh.ASP.NET AJAX is very helpful to do above task.

 To make developer life simple, asp.net Ajax has feature by which entity object can be shared between client browser and web server. There is no need to create array and pass to web service method as parameter.

Let’s have an example as listing below:

STEP 1: Create two projects WebService (i.e. Web Application) and ExposeByService (i.e. Class Library)

                                                    Projects

Add Employee Class in ExposeByService project. Copy below code into that class:

namespace ExposeByService

{

    public  class Employee

    {

        public Employee()

        {

        }

 

       //automatic prpperties

        public int EmpNumber { get; set; }

        public string EmployeeName { get; set; }

 

      

    }

}

STEP 2. Execute the following substeps:

a.  Add webservice in WebService project.

b.   To allow Web Service to be called from script, using ASP.NET AJAX, uncomment System.Web.Script.Services.ScriptService] WebService calss attribute.

c.  To Expose entity object add [System.Web.Script.Services.GenerateScriptType(typeof(ExposeByService.Employee))] attribute to WebService Class.

d.  Add HelloEmployee Test method in webservice:

 

    [WebMethod]

 public ExposeByService.Employee HelloEmployee(ExposeByService.Employee emp)

    {       

        return emp;

  

 }

 

 

 

STEP 3. Execute the following substeps:

a.  Add Default.aspx page in WebSercice Project

b.  Add ScripManager and Service Reference as give in below code

    <asp:ScriptManager ID=”ScriptManager1″ runat=”server” >

    <Services>

    <asp:ServiceReference Path=”~/WebService.asmx” />

    </Services>

    </asp:ScriptManager>

c.  Add Javascript code in Javascript tag:

 

    <script type=”text/jscript” language=”jscript”>

        function CallEmployeeClass() {

 

            //crete object of employee class

            var obj = new ExposeByService.Employee();

            obj.EmpNumber = 123;

            obj.EmployeeName = “Ghajani”;

          //Call HelloEmployee Method

            WebService.HelloEmployee(obj, onReturn,onError);

           

        }

        function onReturn(result) {

          //If you check result here ,it will show EmpNumber and EmployeeName

// as asigned in CallEmployeeClass function.

          

        }

        function onError(result) {

//if you assign empNumber other then Integer

//it will trough dtatype conversion  error without server trip

          

        }

    </script>

 

To test above example, call CallEmployeeClass function from HTML control as common practice.

 Ref:

http://www.asp.net/learn/Ajax/tutorial-05-cs.aspx

Thanks for Reading

Rukhsar Ahmad

Maximum asynchronous request to server

Hi All,
Concurrent request list given below:

Number of concurrent requests of any type (including AJAX, image loads, etc) to a single domain:

  • FF 2: 2
  • FF 3: 6
  • IE 6/7: 2
  • IE 8: 2 on dialup, 6 on broadband
  • Safari: ?
  • Chrome: ?

User can also change browser setting as given below:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
“MaxConnectionsPerServer”=dword:00000004
“MaxConnectionsPer1_0Server”=dword:00000004

Reference:

1. http://stackoverflow.com/questions/561046/how-many-concurrent-ajax-xmlhttprequest-requests-are-allowed-in-popular-browser

2. http://www.codeproject.com/KB/ajax/aspnetajaxtips.aspx?msg=2690115

3. Roundup on Parallel Connections

http://www.stevesouders.com/blog/2008/03/20/roundup-on-parallel-connections/

4. http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.4

Beauty of Prototype in JavaScript

Beauty of Prototype in JavaScript:

JavaScript is true object oriented language. JavaScript object is collection of name and values which are known as properties of an object. In JavaScript object we can add property or method at runtime which are not possible in case of class based object oriented language.

All JavaScript object are inherited from PROTOTYPE native object and have prototype property which is reference to internal prototype object. It means whenever we add property to a JavaScript object it gives reference to internal prototype object.

Let’s have an example to know about prototype.

STEP: 1
There are many ways to create an object in JavaScript one of them is:

//Empty funtion hence there is no property
//in javascript function can act as class

var company =function()
{
// You may add properties here
};

STEP: 2

Create two JavaScript functions “addCompanyName” and “getCompanyName” as given below:

function addCompanyName()
{
var objcompany = new company();//create object of company
objcompany.constructor.prototype.CompanyName = “MyCompany”;//add CompanyName property
}

function getCompanyName()
{
var objcompany = new company();
alert(objcompany.CompanyName);
}

STEP: 3

You are just close to test your example.

Create html page and put above JavaScript function in JavaScript section and add anchars with href (Add MyCompany  Company Name
Get Company Name).

Testing Steps:
1. Browse html page
2. Click on “Add MyCompany Company Name”
3. Click on “Get Company Name”, you will get MyCompany alert message.

This is my first blog if you find any mistake please revert back.

Thanks for Reading
Rukhsar Ahmad