Sunday, June 7, 2015

jquary



change image src
$(this).attr("src", urlAbsolute)

check is check box checked
$('input[name="locationthemes"]:checked');

ASP.NET ADO.NET CACHING

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASP_DEMO.CODE;
using System.Data;
namespace ASP_DEMO
{
    public partial class OfflineDBA : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
   
        DBAccess objdb = new DBAccess();
        protected void btnLoadData_Click(object sender, EventArgs e)
        {
            DataLoad();
        }


        void DataLoad() {


            DataSet ds = null;
            if (Cache["data"] == null)
            {
                string sql = "SELECT     ID, PID, QUESTION, ANSWER FROM  TB_QUESTIONS";
                ds = objdb.Select(sql);
                // ASSING THE PRIMARY KEY
                ds.Tables[0].PrimaryKey = new DataColumn[] {ds.Tables[0].Columns["ID"] };
                Cache["data"] = ds;
                lblMessage.Text = "get data from db";
            }
            else
            {
                ds = (DataSet)Cache["data"];
                lblMessage.Text = "get data from cache";
            }
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            DataLoad();
        }

        protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
        {
         
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            DataLoad();
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            if (Cache["data"] != null)
            {
                DataSet ds = (DataSet)Cache["data"];
                DataRow dr = ds.Tables[0].Rows.Find(e.Keys["ID"]);
                dr["PID"] = e.NewValues["PID"];
                dr["QUESTION"] = e.NewValues["QUESTION"];
                dr["ANSWER"] = e.NewValues["ANSWER"];

                Cache["data"] = ds;
                DataLoad();
            }
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (Cache["data"] != null)
            {
                DataSet ds = (DataSet)Cache["data"];
                DataRow dr = ds.Tables[0].Rows.Find(e.Keys["ID"]);
                ds.Tables[0].Rows.Remove(dr);

                Cache["data"] = ds;
                DataLoad();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Cache.Remove("data");
        }
    }
}

///////////////////////////////////

 <table style="width: 100%;">
        <tr>
            <td>&nbsp;</td>
            <td>
                <asp:Button ID="btnLoadData" runat="server" OnClick="btnLoadData_Click" Text="Load Data" />
            &nbsp;<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>
                <asp:Label ID="lblMessage" runat="server"></asp:Label>
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" >
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
            <asp:BoundField DataField="PID" HeaderText="PID" SortExpression="PID" />
            <asp:BoundField DataField="QUESTION" HeaderText="QUESTION" SortExpression="QUESTION" />
            <asp:BoundField DataField="ANSWER" HeaderText="ANSWER" SortExpression="ANSWER" />
        </Columns>
    </asp:GridView>
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>
             
            </td>
            <td>&nbsp;</td>
        </tr>
    </table>




Thursday, May 28, 2015

Ajax

<script type="text/javascript">
    function send() {
        var person = {
            name: $("#id-name").val(),
            address:$("#id-address").val(),
            phone:$("#id-phone").val()
        }

        $('#target').html('sending..');

        $.ajax({
            url: '/test/PersonSubmit',
            type: 'post',
            dataType: 'json',
            success: function (data) {
                $('#target').html(data.msg);
            },
            data: person
        });
    }
</script>

async ajax call with typescript



module AAA {




    $(document).ready(function () {


        $('#aaa').click(function () {
            callservice()
                .done(function (data) {
                    alert('ts ' + data);
                });

        });
    });
    function callservice(): JQueryDeferred<any> {
        var dfd = jQuery.Deferred();
        $.ajax({
            url: "http://localhost:58171/TTT",
            method: "GET",
            contentType: "application/json; charset=utf-8",
            data: {},
            dataType: "json",
            cache: false,
            success: function (data) {
                var value = data;
                dfd.resolve(value);
            },
            error: function (xhr, textStatus, errorThrown) {
                TsMessage.ShowError(xhr.responseText, xhr);
                dfd.reject();
            }
        });

        return dfd;
    }

}

///////////////////////////////


$.getJSON()

 

 var uri = 'api/products?id=123&name=chamith';

    $(document).ready(function () {
      // Send an AJAX request
      $.getJSON(uri)
          .done(function (data) {
            // On success, 'data' contains a list of products.
            $.each(data, function (key, item) {
              // Add a list item for the product.
              $('<li>', { text: formatItem(item) }).appendTo($('#products'));
            });
          });
    });
////////////////////////

Promise 


// first ajax request
 initLookups_1() {
            var defer = $.Deferred();
            $.ajax({
                url: '/admin/facilitysysconfig/getlookup',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                method: "GET",
                success: (d) => { defer.resolve(d) }
            });
            return defer;
 },
//second ajax request
initLookups_2() {
            var defer = $.Deferred();
            $.ajax({
                url: '/admin/facilitysysconfig/getlookup',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                method: "GET",
                success: (d) => { defer.resolve(d) }
            });
            return defer;
 },

// wait while both 2 request are over

$.when(this.initLookups_1(), this.initLookups_2()).done(function(e){

  // do something ...
   // e ==> {a:initLookups_1_data,b:initLookups_2_data}

});

------------

button loading icon show


required
font awsome


  <button type="button" id="LoginButton" class="btn btn-block btn-primary mt-lg" data-loading-text="<i class='fa fa-spinner fa-spin '></i>   processing ..">
                            Sign in
                        </button>


ajax call

btn.button('loading');
$.ajax({
url:'logging',
complete:()=>{
btn.button('reset');
}

})


Ajax with promise


function getBookingHeader(e) {
   var defer = $.Deferred();
   $.ajax('/reservation/getbookingheader', { data: { bookingId: e },             success: (d) => { defer.resolve(d) } });
            return defer;
    },


 getBookingDetails(172).done((e) => {
    alert(JSON.stringify(e))
 });


Module Design Pattern

var HTMLChanger = (function() { var contents = 'contents' var changeHTML = function() { var element = document.getElementById('attribute-to-change'); element.innerHTML = contents; } return { callChangeHTML: function() { changeHTML(); console.log(contents); } }; })(); HTMLChanger.callChangeHTML(); // Outputs: 'contents' console.log(HTMLChanger.contents); // undefined



CS Events