Archive

Archive for the ‘JQuery’ Category

Asp.Net Jquery fly-to-Basket

December 30, 2010 9 comments

Today me and my friends searching for add to basket with Jquery.We found a good working demo of Jquery fly- to- Basket  at www.webresourcesdepot.com/fly-to-basket-effect-with-jquery/.This Jqury Fly-to-Basket developed with Jquery and PHP.I tried to develop the same fly-to-Basket effect to my exisitng e-commerce project.

Jquery Fly-to-Basket

Products List

Jquery Fly to Basket

<%@ WebHandler Language=’C#’ Class=’Handler’ %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context)
{
if (HttpContext.Current.Request.Form[“action”]!=null)
{
string action = HttpContext.Current.Request.Form[“action”].Trim();
if (action.Equals(“addToBasket”))
{
//call add to Basket
this.AddToCart();
//get CartDetails
string res = this.GetCartDetail();
context.Response.Write(res);
}
else if (action.Equals(“deleteFromBasket”))
{
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
public void AddToCart()
{
//Code for inserting Item into Cart
}
public void DeleteFromCart()
{
}
public string GetCartDetail()
{
}
}
<%@ WebHandler Language='C#' Class='Handler' %>

using System;
using System.Web;

public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context)
    {
        
        if (HttpContext.Current.Request.Form["action"]!=null)
        {
            string action = HttpContext.Current.Request.Form["action"].Trim();
            if (action.Equals("addToBasket"))
            {
                //call add to Basket
                this.AddToCart();
                
                //get CartDetails
                string res = this.GetCartDetail();
                context.Response.Write(res);
                 
              
            }
            else if (action.Equals("deleteFromBasket"))
            {
                
            }
        }
    }
 
    public bool IsReusable 
    {
        get 
        {
            return false;
        }
    }
    public void AddToCart()
    {
       
        //Code for inserting Item into Cart
    }
    public void DeleteFromCart()
    {
        
    }
    public string GetCartDetail()
    {
        return "

";
    }
    
}



Download

Advertisements
Categories: Asp.Net, JQuery

Keeping Your ASP.NET Session Alive Using jQuery

November 3, 2010 Leave a comment

When we are working with Asp.Net,We should take care about Session timeout.The time before timing out is normally configured in the web.config file. Sometimes sessions time out at the most inconvenient time for your users. They could start a page, fill in some data, go to lunch then come back, click next and one of two things happen. Either the user is redirected back to the starting screen,hat means the developer is not checking the session object for a null reference before using it.

One workaround for this is to keep the users session alive by running a small snippet of code which updates a session object.

First we create a Generic Handler.Below is the code for Generic Handler(i.e. SessionAlive.ashx)

public class SessionAlive : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Session["KeepSessionAlive"] = DateTime.Now;
}

public bool IsReusable
{
get
{
return false;
}
}
}


public class KeepSessionAlive : IHttpHandler, IRequiresSessionState

If we didn’t inherit class from this interface, the ASP.NET Session wouldn’t be available and a null reference exception would be thrown. When you inherit a class from IHttpHandler, the main method that you use is ProcessRequest. All this method is doing is touching one ASP.NET session object simply to keep the session alive.

Now we write a javascript to call this SessionAlive.ashx code.For this we are using setInterval function.

Below is the Javascript Code

// <![CDATA[
javascript” type=”text/javascript” src=”http://code.jquery.com/jquery-latest.js”&gt;
// ]]>

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

$(function() {

setInterval(KeepSessionAlive, 10000);        });

function KeepSessionAlive() {                       $.post(“/Shared/KeepSessionAlive.ashx”, null, function() {

$(“#result”).append(“<p>Session is alive and kicking!<p/>”);            });           }

</script>

<h2>Will my session die?</h2>      <div id=”result”></div>

setInterval(KeepSessionAlive, 10000); That function runs a jQuery post to the HttpHandler KeepSessionAlive.ashx:

$.post(“/Shared/KeepSessionAlive.ashx”, null, function() {

This means every 10 seconds the session will be updated behind the scenes. This will give the impression to the user that their session will not time out.

Categories: Asp.Net, JQuery

Control Webcams With JavaScript (jQuery)

September 23, 2010 Leave a comment

jQuery Webcam is a plugin which creates a transparent layer forcommunicating with a camera directly in JavaScript.

This plugin provides three different modes to access a webcam through a small API directly with JavaScript – or more precisely jQuery. Thus, it is possible to bring the image on a Canvas (callback mode), to store the image on the server (save mode) and to stream the live image of the Flash element on a Canvas (stream mode).

Souce: http://www.xarg.org/project/jquery-webcam-plugin/

Categories: JQuery