Thursday, July 5, 2012

Jquery Method to get querystring values

Jquery Method to get querystring values

Reference link :http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
I like the way of stack overflow user as they help the users :

function getParameterByName(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

Friday, May 18, 2012

 

Task Scheduling using GLOBAL file

 

<%@ Application Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Timers" %>
<%@ Import Namespace="System.Net.Mail" %>




<script runat="server">
    void Application_Start(object sender, EventArgs e)
    {
        System.Timers.Timer t = new System.Timers.Timer(30000);
        t.Elapsed += new ElapsedEventHandler(t_Elapsed);
        t.AutoReset = true;
        t.Enabled = true;
    }
    private void t_Elapsed(object sender, ElapsedEventArgs e)
    {
        SmtpClient smtpClient = new SmtpClient();
        System.Net.NetworkCredential basicCredential =
            new System.Net.NetworkCredential("a@a.com", "a");
        MailMessage message = new MailMessage();
        MailAddress fromAddress = new MailAddress("a@a.com");

        smtpClient.Host = "smtp.a.com";
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = basicCredential;

        message.From = fromAddress;
        message.Subject = "your subject";
        //Set IsBodyHtml to true means you can send HTML email.
        message.IsBodyHtml = true;
        message.Body = "<h1>your message body</h1>";
        message.To.Add("a@a.com");

        try
        {
            smtpClient.Send(message);
        }
        catch (Exception ex)
        {
            //Error, could not send the message
            Response.Write(ex.Message);
        }

    }   



    void Application_End(object sender, EventArgs e)
    {
       



    }
       

    void Application_Error(object sender, EventArgs e)
    {
       



    }


    void Session_Start(object sender, EventArgs e)
    {
       



    }


    void Session_End(object sender, EventArgs e)
    {
       



    }
      

</script>
SEND EMAIL in C#




SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential =
    new NetworkCredential("username", "password");
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("from@yourdomain.com");

smtpClient.Host = "mail.mydomain.com";
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;

message.From = fromAddress;
message.Subject = "your subject";
//Set IsBodyHtml to true means you can send HTML email.
message.IsBodyHtml = true;
message.Body = "<h1>your message body</h1>";
message.To.Add("to@anydomain.com");

try
{
    smtpClient.Send(message);
}
catch(Exception ex)
{
    //Error, could not send the message
    Response.Write(ex.Message);
}

Wednesday, April 11, 2012

Generic Javscript Validation

Here is the JS code
function Validate(objForm) {
    var arrValidated = new Array();
    for (var i = 0; i < objForm.elements.length; i++) {
        var element = objForm.elements[i];
        var elName = element.name;
        if ((!elName) || (elName.length == 0) || (arrValidated[elName]))
            continue;
        arrValidated[elName] = true;
        var validationType = element.getAttribute("validate");
        if ((!validationType) || (validationType.length == 0))
            continue;
        var strMessages = element.getAttribute("msg");
        if (!strMessages)
            strMessages = "";
        var arrMessages = strMessages.split("|");
        var arrValidationTypes = validationType.split("|");
        for (var j = 0; j < arrValidationTypes.length; j++) {
            var curValidationType = arrValidationTypes[j];
            var blnValid = true;
            switch (curValidationType) {
                case "not_empty":
                    blnValid = ValidateNotEmpty(element);
                    break;
                case "integer":
                    blnValid = ValidateInteger(element);
                    break;
                case "number":
                    blnValid = ValidateNumber(element);
                    break;
                case "email":
                    blnValid = ValidateEmail(element);
                    break;
                case "phone":
                    blnValid = ValidatePhone(element);
                    break;
                default:
                    try {
                        blnValid = eval(curValidationType + "(element)");
                    }
                    catch (ex) {
                        blnValid = true;
                    }
            }
            if (blnValid == false) {
                var message = "invalid value for " + element.name;
                if ((j < arrMessages.length) && (arrMessages[j].length > 0))
                    message = arrMessages[j];
                InsertError(element, message);
                if ((typeof element.focus == "function") || (element.focus)) {
                    element.focus();
                }
                return false;
            }
            else
                ClearError(element);
        }
    }
    return true;
}

//Empty Validation

function ValidateNotEmpty(objElement) {
    var strValue = GetElementValue(objElement);
    var blnResult = true;
    if (allTrim(strValue) == "") //check for nothing
    {
        blnResult = false;
    }
    return blnResult;
}


//Integer Validation
function ValidateInteger(objElement) {
    var strString = GetElementValue(objElement);
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}
//Number Validation
function ValidateNumber(objElement)
// check for valid numeric strings
{
    var strString = GetElementValue(objElement);
    var strValidChars = ".0123456789"; //decimal ok
    var strChar;
    var blnResult = true;
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}



//Email Validation
function ValidateEmail(objElement) {
    // Will check for @, period after @ and text in between
    var strValue = GetElementValue(objElement);
    var in_space = strValue.indexOf(" ");
    if (in_space != -1)
    { return false; }
    var len = strValue.length;
    var alpha = strValue.indexOf("@");
    var last_alpha = strValue.lastIndexOf("@");
    if (alpha != last_alpha)
    { return false; }
    // No @, in first position, or name too short
    if (alpha == -1 || alpha == 0 || len < 6)
    { return false; }
    var last_p = strValue.lastIndexOf(".");
    // Be sure period at least two spaces after @, but not last char.
    if (last_p - alpha < 2 || last_p == (len - 1))
    { return false; }
}


//Valid PhoneNumber

function ValidatePhone(objElement) {
    // non-digit characters which are allowed in phone numbers
    var phoneNumberDelimiters = "()- ";
    // characters which are allowed in international phone numbers
    // (a leading + is OK)
    var validWorldPhoneChars = phoneNumberDelimiters + "+";
    // Minimum no of digits in an international phone no.
    var minDigitsInIPhoneNumber = 10;
    var strValue = GetElementValue(objElement);
    s = stripCharsInBag(strValue, validWorldPhoneChars);
    return (ValidateInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function GetElementValue(objElement) {
    var result = "";
    switch (objElement.type) {
        case "text":
        case "hidden":
        case "textarea":
        case "password":
            result = objElement.value;
            break;
        case "select-one":
        case "select":
            if (objElement.selectedIndex >= 0)
                result = objElement.options[objElement.selectedIndex].value;
            break;
        case "radio":
        case "checkbox":
            for (var i = 0; i < objElement.form.elements.length; i++) {
                if (objElement.form.elements[i].name == objElement.name) {
                    if (objElement.form.elements[i].checked)
                        result += objElement.form.elements[i].value + ",";
                }
            }
            break;
    }
    return result;
}

function InsertError(element, strMessage) {
    if ((element.form.getAttribute("show_alert")) && (element.form.getAttribute("show_alert") != "0")) {
        alert(strMessage);
        return;
    }
    var strSpanID = element.name + "_val_error";
    var objSpan = document.getElementById(strSpanID);
    if (!objSpan) {
        if ((element.type == "radio") || (element.type == "checkbox")) {
            for (var i = 0; i < element.form.elements.length; i++) {
                if (element.form.elements[i].name == element.name) {
                    element = element.form.elements[i];
                }
            }
        }
        objSpan = document.createElement("span");
        objSpan.id = strSpanID;
        objSpan.className = "validation_error";
        var nodeAfter = 0;
        var nodeParent = element.parentNode;
        for (var i = 0; i < nodeParent.childNodes.length; i++) {
            if (nodeParent.childNodes[i] == element) {
                if (i < (nodeParent.childNodes.length - 1))
                    nodeAfter = nodeParent.childNodes[i + 1];
                break;
            }
        }
        if ((!nodeAfter) && (nodeParent.parentNode)) {
            nodeParent = nodeParent.parentNode;
            for (var i = 0; i < nodeParent.childNodes.length; i++) {
                if (nodeParent.childNodes[i] == element.parentNode) {
                    if (i < (nodeParent.childNodes.length - 1))
                        nodeAfter = nodeParent.childNodes[i + 1];
                    break;
                }
            }
        }

        if (nodeAfter)
            nodeParent.insertBefore(objSpan, nodeAfter);
        else
            document.body.appendChild(objSpan);
    }
    objSpan.innerHTML = strMessage;
}

function ClearError(element) {
    var strSpanID = element.name + "_val_error";
    var objSpan = document.getElementById(strSpanID);
    if (objSpan) {
        objSpan.innerHTML = "";
    }
}

function allTrim(cValue) {
    var lDone = false;
    while (lDone == false) {
        if (cValue.length == 0) { return cValue; }
        if (cValue.indexOf(' ') == 0) { cValue = cValue.substring(1); lDone = false; continue; }
        else { lDone = true; }
        if (cValue.lastIndexOf(' ') == cValue.length - 1) { cValue = cValue.substring(0, cValue.length - 1); lDone = false; continue; }
        else { lDone = true; }
    }
    return cValue;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string’s characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        // Check that current character isn’t whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

HTML :
<form action="JsValidation.aspx" show_alert="1" onSubmit="return Validate(this);">

First Name <input type="Text" name="FirstName" maxlength="25" validate="not_empty" msg="First Name is Required" /><br/>

Email <input type="text" name="Email" maxlength="25" validate="email" msg="Email is Required" /><br/>

<input type="submit" value="Go">

</form>

Thursday, March 8, 2012

MVC step by step guide for learning

http://www.codeproject.com/Articles/207797/Learn-MVC-Model-view-controller-Step-by-Step-in-7#So,%20what%E2%80%99s%20the%20agenda

Thursday, March 1, 2012

Saturday, February 25, 2012

page load event with working example in c#

I have google a lot for working example of page events in C# but i was not able to find code in c# but found in vb. then i decided to write my own example in c# , so that it may help all my .net friends.
Here are two pages code one is .aspx and other one is .aspx.cs :

Default.aspx : 
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
 <asp:PlaceHolder runat="server" ID="LabelPlaceHolder" >
     <%--<asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label>--%>
 </asp:PlaceHolder>
    <br />
    <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
</asp:Content>
and  the code behind file for this page is  :
CODE Behind File :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Default3 : System.Web.UI.Page
{
   
    void Page_Error(object sender, EventArgs e)
    {
        //This is for getting error from page and handing them accordingly
    }
    void Page_PreInit(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            Label lblMessage = new Label();
            lblMessage.ID = "lblMessage";
            lblMessage.Width = 500;
            lblMessage.Text = "Dynamically created control.";
            ContentPlaceHolder ContentPlaceHolder1 = (ContentPlaceHolder)Master.FindControl("MainContent");
            PlaceHolder LabelPlaceHolder = (PlaceHolder)ContentPlaceHolder1.FindControl("LabelPlaceHolder");
            LabelPlaceHolder.Controls.Add(lblMessage);
        }
    }
    void Page_Init(object sender, EventArgs e)
    {

        ContentPlaceHolder ContentPlaceHolder1 = (ContentPlaceHolder)Master.FindControl("MainContent");
        PlaceHolder LabelPlaceHolder = (PlaceHolder)ContentPlaceHolder1.FindControl("LabelPlaceHolder");
        Label lblMessage = (Label)LabelPlaceHolder.FindControl("lblMessage");
        lblMessage.ForeColor = System.Drawing.Color.Black;
        Trace.Write("Page_Init " + DateTime.Now.ToString());
    }
    void Page_InitComplete(object sender, EventArgs e)
    {
        ContentPlaceHolder ContentPlaceHolder1 = (ContentPlaceHolder)Master.FindControl("MainContent");
        PlaceHolder LabelPlaceHolder = (PlaceHolder)ContentPlaceHolder1.FindControl("LabelPlaceHolder");
        Label lblMessage = (Label)LabelPlaceHolder.FindControl("lblMessage");
        lblMessage.ToolTip = "Tooltip added during InitComplete event.";
        ViewState["Author"] = "Robert S. Robbins";
        System.Diagnostics.Trace.WriteLine("Page_InitComplete " + DateTime.Now.ToString());
    }
    void Page_PreLoad(object sender, EventArgs e)
    {
        System.Diagnostics.Trace.WriteLine(ViewState.Values.Count, "ViewState Count");
        System.Diagnostics.Trace.WriteLine(Request.ServerVariables["SCRIPT_NAME"], "Script Name");
        System.Diagnostics.Trace.WriteLine("Page_PreLoad " + DateTime.Now.ToString());
    }
    void Page_Load(object sender, EventArgs e)
    {
        SqlConnection cn;

        SqlCommand objSqlCommand = new SqlCommand();

        cn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Northwind"].ToString();

        cn.Open();

        objSqlCommand.Connection = cn;

        objSqlCommand.CommandText = "SELECT ProductID, ProductName, UnitPrice FROM Products ORDER BY ProductName";

        DataSet objDataSet = new DataSet();

        SqlDataAdapter objSqlDataAdapter = new SqlDataAdapter();

        objSqlDataAdapter.SelectCommand = objSqlCommand;

        objSqlDataAdapter.Fill(objDataSet);

        GridView1.DataSource = objDataSet;

        GridView1.DataBind();

        cn.Close();

        System.Diagnostics.Trace.WriteLine("Page_Load " + DateTime.Now.ToString());
    }
    void Page_LoadComplete(object sender, EventArgs e)
    {
        System.Diagnostics.Trace.WriteLine(GridView1.Rows[5].Cells[01].Text, "Row 6, Cell 2");
        System.Diagnostics.Trace.WriteLine("Page_LoadComplete " + DateTime.Now.ToString());
    }
    void Page_PreRender(object sender, EventArgs e)
    {
        ContentPlaceHolder ContentPlaceHolder1 = (ContentPlaceHolder)Master.FindControl("MainContent");
        PlaceHolder LabelPlaceHolder = (PlaceHolder)ContentPlaceHolder1.FindControl("LabelPlaceHolder");
        
        GridView GridView1= (GridView)ContentPlaceHolder1.FindControl("GridView1");

        GridViewRow objGridViewRow;

        objGridViewRow = new GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);

        TableCell objTableCell= new TableCell();

        LiteralControl literal= new LiteralControl();

        literal.Text = "Northwind Products";

        objTableCell.Controls.Add(literal);

        objTableCell.ColumnSpan = 3;

        objTableCell.HorizontalAlign = HorizontalAlign.Center;

        objTableCell.ForeColor = System.Drawing.Color.White;

        objTableCell.BackColor = System.Drawing.Color.Black;

        objGridViewRow.Cells.Add(objTableCell);

        GridView1.Controls[0].Controls.AddAt(0, objGridViewRow);

        System.Diagnostics.Trace.WriteLine("Page_PreRender " +DateTime.Now();
    }
    void Page_PreRenderComplete(object sender, EventArgs e)
    {
        ContentPlaceHolder ContentPlaceHolder1 = (ContentPlaceHolder)Master.FindControl("MainContent");
        PlaceHolder LabelPlaceHolder = (PlaceHolder)ContentPlaceHolder1.FindControl("LabelPlaceHolder");
        GridView GridView1 = (GridView)ContentPlaceHolder1.FindControl("GridView1");
        GridView1.HeaderRow.Cells[0].Text = "Product ID";
        GridView1.HeaderRow.Cells[1].Text = "Product Name";
        GridView1.HeaderRow.Cells[2].Text = "Unit Price";
    }
    void Page_SaveStateComplete(object sender, EventArgs e)
    {
        ViewState["Date"] = DateTime.Now.ToString();
        System.Diagnostics.Trace.WriteLine("Page_SaveStateComplete " + DateTime.Now.ToString());
    }
    void Page_Unload(object sender, EventArgs e)
    {
        System.Diagnostics.Trace.WriteLine(ViewState.Values.Count, "ViewState Count");

    }
   
   
}

-----------------------------------------------------------------------------------------
I have used this code in vs2010.

Try using breakpoin with every event . and then debug .
By using Debugger . you can check which event fires first and what can we do with each event..

HOPE THIS HELPS  :)

Thanks

Monday, January 30, 2012

Creating Exe in C# and Deploying sql server with exe

http://balanagaraj.wordpress.com/2007/05/29/create-exe-or-setup-file-in-net-windows-application/

Monday, January 23, 2012

My RESUME




Er. Gourav Khanna

Mobile No: +91-9988124581
 
gauravkhanna1058@yahoo.co.in
gauravkhanna1058@gmail.com




Objective



To seek the challenging position in Software
development industry that needs innovation, creativity, dedication and
enable me to continue to work in a challenging and fast paced environment,
leveraging my current knowledge and fostering creativity with many
learning opportunities.

Summary


Total 3 years of competitive experience in IT industry (Dot Net, SQL server 2008,2000)        
 and 6 month of industrial training experience.


Experience of working in the Software development life cycle involving
development, documentation and maintenance.
·     
Good work ethics with good
communication and interpersonal skills.
·       
Capable to delve into the new leading Technologies.
    Ability to work well in both a team environment and individual environment.

 


Technical Skills


Web Technologies

Visual
Studio-2010,Visual Studio-2008,Visual Studio-2005,JavaScript,Sql 2008

Advance Technology

Basic knowledge of Silverlight, WPF,
WCF ,MVC Architecture



Languages

C#.Net, JavaScript, JQuery , Html ,
Css



Databases

SQL Server 2008,2005,2000
Operating Systems

Windows 2000/98/XP

 
Experience Summary




 


     Total IT
Experience: 3 Years


 

·       

Total IT Experience of 3 Months in Software
Industry.

·       

Experience in ASP.Net using C# & VB Language,
JavaScript, SQL Server 2000, 2005, 2008.


 

 



Work Experience





 

§ 


Currently

working with Gray Cell Technologies
Exports, Chandigarh
as Software Engineer from
April 3rd, 2010

§ 

Worked as Software Engineer in
Intiger.com
, Chandigarh from
August 1st, 2009.   


 

 


Professional Experience:



MoveForFree



Website




Environment


ASP.NET 2.0, C#.Net, JavaScript, JQuery, Custom Ajax

 



Database


SQL Server 2000



Role


Team Work



Team Size


6


Responsibilities

Web developer.



Description
:
MoveForFree.com began advertising in June of 2000 and very quickly became
the fastest growing locator service in the country. Website provides services in
Dallas, Fort Worth, Houston, Austin, Atlanta and San Antonio and represents
thousands of apartment communities across the country. Moveforfree.com’s
services are similar to a traditional apartment locating service. However,
website provides a free move unlike any of our traditional apartment locating
competitors. Website provides users with up to date information on properties
including prices, floor plans, amenities and policies.





Quote Builder



Website




Environment


ASP.Net 3.5, C# Language, JavaScript

 



Database

MYSQL



Role


Team Work



Team Size


4


Responsibilities

Web developer.


Description
:
Quote builder is a secure FBI website which sells camera and other parts
including hardware and cameras  depends on
their user roles.
Their goal is to enhance security
enforcement on all levels.


 

National vehicle location service




Website

secure



Environment


ASP.Net 3.5,C# Language, JavaScript

 



Database

SQL Server 2008



Role


Team Work



Team Size


4


Responsibilities

Web developer.


Description
:
NVLS is also a secure FBI site  which
is
Detects and records


license plate numbers on moving cars, and compares them in real-time to
"Hot-List" data to offer alarms where and when needed - specifically for
proactive security.

 


 Nancarrow realty group




Website


http://www.nancarrowrealtygroup.com/



Environment


ASP.Net with C# Language, JavaScript,Bing Map API’s

 



Database

SQL Server 2005



Role


Team Work



Team Size





Responsibilities

Involved in
Bing Map API’s Implementation


Description
:
A real estate website using Bing maps Api’s

 


Vision Dream board system




Desktop




Environment


WPF using c#, xml

 



Database

SQL Server 2008



Role


Team Work



Team Size


5


Responsibilities



 


Description : -


This project is a desktop application i.e. installer for creating/managing own
Image library, Video library and music library . Installer include creating some
predefined categories like Weath, Heath, Kids, Spritual, Relationship with the
functionality of creating own custom category. Installer also includes slide
show and run/create/save vision board by using WPF application development.

 



Carpooling System



Website




Environment


ASP.Net with C# Language, JavaScript, Google Map API’s

 



Database

SQL Server 2005



Role


Team Work



Team Size





Responsibilities

Involved in
Google Map API’s Implementation, Ajax Pro.


Description
:
mapmycarpool.com System includes sharing of vehicles in India. It implements powerful Google Map API’s to
show maps of different locations. Interaction between client side and server
side code using Ajax Pro. Facilities include live chat, storing of routes for
specific users, searching maps created by different-2 users.

 


College Website



Website

College Website.



Environment


ASP.Net with C# Language




Role


Individual


Responsibilities


Developer



Description
:

The objective of project is to redesign existing website by adding some new features
in existing site
.

 



CO-CURRICULAR ACTIVITIES




§ 

Created my own website i.e “www.videoonfacebook.com”

§ 

Participated in Blood donation camp organized in Office and College.

§ 

Sports Participation :

o   


Participated in Athletics Competition

o   


Inter College Cricket Player

 

 



Academic Credentials





Degree



  Year


Board/University

Percentage



Class


B.Tech (I.T)


  2009


Punjab

Technical University


75.00 %

  First Class



Intermediate


  2005


P.S.E.B.


57.00 %

  Second

class





10th


  2003


P.S.E.B.


75.00 %

  First

class










 

 

 

 

 

 

 

 



Personal Information:





Name



Gourav Khanna



Date Of Birth


15th April,1988



Languages Known


English, Hindi, Punjabi



Marital Status





Single



Hobbies


Reading Articles ,Surfing, Listening Music



Address

#1058/B, K.s.m Road,Rajpura

 



Email