Asp Dot Net Tricks

validation code

 function YourButtonClickEvent() {
            var validation = Page_ClientValidate();
            if (!validation) {
                for (var i = 0; i < Page_Validators.length; i++) {
                    if (!Page_Validators[i].isvalid) {
                        $("#" + Page_Validators[i].controltovalidate).css("border-color", "red");
                    }
                }
            }
            return val;
        }

execute code

//Create user starts
        SqlParameter[] spar = new SqlParameter[12];
        spar[0] = new SqlParameter("@UserEmail", txtEmailAddrRegis.Text.Trim());
        spar[1] = new SqlParameter("@Password", txtPasswordRegis.Text.Trim());
        spar[2] = new SqlParameter("@Name", txtNameRegis.Text.Trim());
        spar[3] = new SqlParameter("@Country", app.getCurrentCountry());
        spar[4] = new SqlParameter("@intRetVal", 0);
        spar[4].Direction = ParameterDirection.Output;
        spar[5] = new SqlParameter("@LastName", txtLast.Text.Trim());
        spar[6]=new SqlParameter("@City",txtCIty.Text.Trim());
       
        spar[8]=new SqlParameter("@Zip",txtZip.Text.Trim());
        spar[9]=new SqlParameter("@Contact",txtPhone.Text.Trim());
        spar[10]=new SqlParameter("@Fax",txtFax.Text.Trim());
        spar[11] = new SqlParameter("@Address", txtAddress.Text.Trim());
        if (drpCntrySelFront.SelectedItem.Text == "India")
        {
            spar[7] = new SqlParameter("@State", dpdstate.SelectedItem.Text);
        }
        else
        {
            spar[7] = new SqlParameter("@State", txtState.Text.Trim());
        }
       
        sqlGet.executeNonQuery("[dbo].[UserCreate]", spar, CommandType.StoredProcedure);

        if (Convert.ToString(spar[4].Value) == "0")
        {
            lblRegisterMsg.ForeColor = System.Drawing.Color.Red;
            lblRegisterMsg.Text = "This Email address is already registered with us.";
        }


jquery validation and calculation

 
        $(document).ready(function () {
         $(function () {
            $('.allow_only_decimal').on('keypress', function (e) {
                return isNumber(e, this);
            });
        });
            $.fn.SetDecimalOnly = function () {
                return this.each(function () {
                    $(this).keydown(function (e) {
                        var key = e.charCode || e.keyCode || 0;
                        return (
                            key == 8 ||
                            key == 9 ||
                            key == 13 ||
                            key == 46 ||
                            key == 110 ||
                            key == 190 ||
                            (key >= 35 && key <= 40) ||
                            (key >= 48 && key <= 57) ||
                            (key >= 96 && key <= 105));
                    });
                });
            };
            $('#btnSave').on('click', function (e) {
                e.preventDefault();
                var flag = true;
                $('#tbodyAddGrant tr input:text').each(function () {
                    if ($(this).val() == '' || $(this).val() == '.' || $(this).val() == '-' || $(this).val() == '.-' || $(this).val() == '-.') {
                        if ($(this).attr('id').indexOf('Total') < 0) {
                            $(this).focus();
                            $(this).addClass('error_input');
                            flag = false;
                        }
                    } else {
                        $(this).removeClass('error_input');
                    }
                });
                
                if (flag) {
                    $('#btnSavePostback').trigger('click');
                }
            });
            $('#tbodyAddGrant').each(function () {
                var tbody = $(this);
                tbody.find('input:text').each(function () {
                    //$(this).SetDecimalOnly();
                    $(this).addClass('allow_only_decimal');
                    $(this).attr('maxlength', '7');
                    if ($(this).attr('id').indexOf('Total') >= 0) {
                        $(this).attr('readonly', true);
                    }
                    else {
                        $(this).attr('onblur', 'Calculate_Total($(this))');
                    }
                });
            });
        });
        function isNumber(evt, element) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (
                (charCode != 45 || $(element).val().indexOf('-') != -1) &&      // “-” CHECK MINUS, AND ONLY ONE.
                (charCode != 46 || $(element).val().indexOf('.') != -1) &&      // “.” CHECK DOT, AND ONLY ONE.
                ((charCode < 48 || charCode > 57) && charCode != 8))
                return false;
            return true;
        }

      

        function Calculate_Total(txt) {
            var id = txt.attr('id');
            var IDs = id.split('_');
            var Value_2012_13 = 0;
            var Value_2013_14 = 0;
            var Value_2014_15 = 0;
            var Value_2015_16 = 0;
            var Value_2016_17 = 0;
            var TotalEXp = 0;
            var Unspent = 0;
            if ($('#txt_2012_13_' + IDs[3] + '').val() != '') {
                Value_2012_13 = parseFloat($('#txt_2012_13_' + IDs[3] + '').val());
            }
            if ($('#txt_2013_14_' + IDs[3] + '').val() != '') {
                Value_2013_14 = parseFloat($('#txt_2013_14_' + IDs[3] + '').val());
            }
            if ($('#txt_2014_15_' + IDs[3] + '').val() != '') {
                Value_2014_15 = parseFloat($('#txt_2014_15_' + IDs[3] + '').val());
            }
            if ($('#txt_2015_16_' + IDs[3] + '').val() != '') {
                Value_2015_16 = parseFloat($('#txt_2015_16_' + IDs[3] + '').val());
            }
            if ($('#txt_2016_17_' + IDs[3] + '').val() != '') {
                Value_2016_17 = parseFloat($('#txt_2016_17_' + IDs[3] + '').val());
            }
            var TOTAL = Value_2012_13 + Value_2013_14 + Value_2014_15 + Value_2015_16 + Value_2016_17;
            $('#txt_Total_' + IDs[3] + '').val(TOTAL.toFixed(2));


            var ALL_31 = 0;
            var ALL_35 = 0;
            var ALL_36 = 0;
            if ($('#txt_' + IDs[1] + '_' + IDs[2] + '_31').val() != '') {
                ALL_31 = parseFloat($('#txt_' + IDs[1] + '_' + IDs[2] + '_31').val());
            }
            if ($('#txt_' + IDs[1] + '_' + IDs[2] + '_35').val() != '') {
                ALL_35 = parseFloat($('#txt_' + IDs[1] + '_' + IDs[2] + '_35').val());
            }
            if ($('#txt_' + IDs[1] + '_' + IDs[2] + '_36').val() != '') {
                ALL_36 = parseFloat($('#txt_' + IDs[1] + '_' + IDs[2] + '_36').val());
            }
            $('#txt_' + IDs[1] + '_' + IDs[2] + '_Total').val(ALL_31 + ALL_35 + ALL_36);


            var Total_2012_13 = 0;
            var Total_2013_14 = 0;
            var Total_2014_15 = 0;
            var Total_2015_16 = 0;
            var Total_2016_17 = 0;
            var Total_Total = 0;
            if ($('#txt_2012_13_Total').val() != '') {
                Total_2012_13 = parseFloat($('#txt_2012_13_Total').val());
            }
            if ($('#txt_2013_14_Total').val() != '') {
                Total_2013_14 = parseFloat($('#txt_2013_14_Total').val());
            }
            if ($('#txt_2014_15_Total').val() != '') {
                Total_2014_15 = parseFloat($('#txt_2014_15_Total').val());
            }
            if ($('#txt_2015_16_Total').val() != '') {
                Total_2015_16 = parseFloat($('#txt_2015_16_Total').val());
            }
            if ($('#txt_2016_17_Total').val() != '') {
                Total_2016_17 = parseFloat($('#txt_2016_17_Total').val());
            }
            var Total_Total = Total_2012_13 + Total_2013_14 + Total_2014_15 + Total_2015_16 + Total_2016_17;
            $('#txt_Total_Total').val(Total_Total.toFixed(2));



        }
   

Sqlget

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;


/// 
/// Summary description for sqlGet
/// 
public static class sqlGet
{
    public static DataSet getDataset(string cmdName, SqlParameter[] cmpPar, CommandType cmdType)
    {

        
        string sqlConnstr = ConfigurationManager.ConnectionStrings["PCB_ConnectionString"].ConnectionString;
        SqlConnection sqlConn = new SqlConnection(sqlConnstr);

        SqlCommand sqlCmd = sqlConn.CreateCommand();
        sqlCmd.CommandText = cmdName;
        sqlCmd.CommandType = cmdType;

        try
        {
            foreach (SqlParameter par in cmpPar)
            {
                sqlCmd.Parameters.Add(par);
            }
        }
        catch (Exception ex)
        {
        }

        DataSet ds = new DataSet();

        SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
        sqlConn.Open();
        da.Fill(ds);
        sqlConn.Close();

        return ds;

    }

    public static DataSet getDataset(string cmdName, CommandType cmdType)
    {
        string sqlConnstr = ConfigurationManager.ConnectionStrings["PCB_ConnectionString"].ConnectionString;
        SqlConnection sqlConn = new SqlConnection(sqlConnstr);

        SqlCommand sqlCmd = sqlConn.CreateCommand();
        sqlCmd.CommandText = cmdName;
        sqlCmd.CommandType = cmdType;

        DataSet ds = new DataSet();

        SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
        sqlConn.Open();
        da.Fill(ds);
        sqlConn.Close();

        return ds;

    }

    public static DataTable getDataTable(string cmdName, SqlParameter[] cmpPar, CommandType cmdType)
    {
        string sqlConnstr = ConfigurationManager.ConnectionStrings["PCB_ConnectionString"].ConnectionString;
        SqlConnection sqlConn = new SqlConnection(sqlConnstr);

        SqlCommand sqlCmd = sqlConn.CreateCommand();
        sqlCmd.CommandText = cmdName;
        sqlCmd.CommandType = cmdType;

        try
        {
            foreach (SqlParameter par in cmpPar)
            {
                sqlCmd.Parameters.Add(par);
            }
        }
        catch (Exception ex)
        {
        }

        DataTable dt = new DataTable();

        SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
        sqlConn.Open();
        da.Fill(dt);
        sqlConn.Close();

        return dt;

    }

    public static DataTable getDatatable(string cmdName, CommandType cmdType)
    {
        string sqlConnstr = ConfigurationManager.ConnectionStrings["PCB_ConnectionString"].ConnectionString;
        SqlConnection sqlConn = new SqlConnection(sqlConnstr);

        SqlCommand sqlCmd = sqlConn.CreateCommand();
        sqlCmd.CommandText = cmdName;
        sqlCmd.CommandType = cmdType;

        DataTable dt = new DataTable();

        SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
        sqlConn.Open();
        da.Fill(dt);
        sqlConn.Close();

        return dt;

    }


    public static void executeNonQuery(string cmdName, SqlParameter[] cmpPar, CommandType cmdType)
    {
        string sqlConnstr = ConfigurationManager.ConnectionStrings["PCB_ConnectionString"].ConnectionString;
        SqlConnection sqlConn = new SqlConnection(sqlConnstr);

        SqlCommand sqlCmd = sqlConn.CreateCommand();
        sqlCmd.CommandText = cmdName;
        sqlCmd.CommandType = cmdType;

        try
        {
            foreach (SqlParameter par in cmpPar)
            {
                sqlCmd.Parameters.Add(par);
            }
        }
        catch (Exception ex)
        {
        }

        sqlConn.Open();
        sqlCmd.ExecuteNonQuery();
        sqlConn.Close();

    }


    public static void executeNonQuery(string cmdName , CommandType cmdType)
    {
        string sqlConnstr = ConfigurationManager.ConnectionStrings["PCB_ConnectionString"].ConnectionString;
        SqlConnection sqlConn = new SqlConnection(sqlConnstr);

        SqlCommand sqlCmd = sqlConn.CreateCommand();
        sqlCmd.CommandText = cmdName;
        sqlCmd.CommandType = cmdType;

        sqlConn.Open();
        sqlCmd.ExecuteNonQuery();
        sqlConn.Close();

    }


    public static void executeNonQueryRef(string cmdName, ref SqlParameter[] cmpPar, CommandType cmdType)
    {
        string sqlConnstr = ConfigurationManager.ConnectionStrings["PCB_ConnectionString"].ConnectionString;
        SqlConnection sqlConn = new SqlConnection(sqlConnstr);

        SqlCommand sqlCmd = sqlConn.CreateCommand();
        sqlCmd.CommandText = cmdName;
        sqlCmd.CommandType = cmdType;

        try
        {
            foreach (SqlParameter par in cmpPar)
            {
                sqlCmd.Parameters.Add(par);
            }
        }
        catch (Exception ex)
        {
        }

        sqlConn.Open();
        sqlCmd.ExecuteNonQuery();
        sqlConn.Close();

    }


}

Bootstrap Resources