Thursday, March 27, 2014

Fibonacci series

 Public Sub ChildClass1()
            Dim t1 As Integer = 0
            Dim t2 As Integer = 1
            Dim display As Integer = 0
            Dim num As Integer = 200
            While display < num
                Console.WriteLine(display)
                t1 = t2
                t2 = display
                display = t1 + t2
            End While

Tuesday, March 25, 2014

CRUD Command in entity framework

  //select command        
         int idToupdate = Convert.ToInt32(Request.QueryString["id"].ToString());
            db_testCon db = new db_testCon();
            tblCustomer tb = db.tblCustomers.Single(p => p.CustomerID == idToupdate);
            TextBox1.Text = tb.City;          
           
            and            
        db_testModel.db_testcon db = new db_testcon();
        Repeater1.DataSource = db.tblCustomer;
        Repeater1.DataBind();
           
            //update  commnd
           
             int idToupdate = Convert.ToInt32(Request.QueryString["id"].ToString());
        db_testCon db = new db_testCon();
        tblCustomer tb = db.tblCustomers.SingleOrDefault(a=>a.CustomerID==idToupdate);
        tb.City = TextBox1.Text;
        db.SaveChanges();
       
       
        //Add Command
       
        db_testcon db = new db_testcon();
        tblCustomer tb = new tblCustomer();
        tb.CompanyName = TextBox1.Text;
        tb.ContactName = TextBox2.Text;
        tb.City = TextBox3.Text;
        db.tblCustomer.AddObject(tb);
        if (db.SaveChanges() == 1) { Response.Redirect("et.aspx"); }
       
       
        //delete command
        int idToupdate = Convert.ToInt32(Request.QueryString["id"].ToString());
        db_testcon db1 = new db_testcon();
        tblCustomer tb = db1.tblCustomer.SingleOrDefault(a => a.CustomerID == idToupdate); 
        db1.tblCustomer.DeleteObject(tb);
        db1.SaveChanges();

Wednesday, March 19, 2014

How to get Ip adress from json?

1. jsonip.com: is a free utility service that returns a client's IP address in a JSON object with support for JSONP, CORS, and direct requests. It serves millions of requests each day for websites, servers, mobile devices and more from all around the world.

All you need to do is to make a call to jsonip.com.
1$(document).ready(function () {
2    $.get('http://jsonip.com', function (res) {
3        $('p').html('IP Address is: ' + res.ip);
4    });
5});

2. Smart-IP.net
: Smart IP for today is one of the leading services providing to it's users all the required information about IP-addresses and everything related to them.
1$(document).ready(function () {
2    $.getJSON('http://smart-ip.net/geoip-json?callback=?', function(data) {
3        $('p').html('My IP Address is: ' + data.host);
4    });
5});
Along with the IP address, this service also provide Geo location details as well like Country, latitude, longitude etc. Following are the properties which are returned as JSON response by this service.
1data.host;
2data.countryName;
3data.countryCode;
4data.city;
5data.region;
6data.latitude;
7data.longitude;
8data.timezone;

jQuery code to check if all textboxes are empty

$(document).ready(function() {
02    $('#btnSubmit').click(function(e) {
03        var isValid = true;
04        $('input[type="text"]').each(function() {
05            if ($.trim($(this).val()) == '') {
06                isValid = false;
07                $(this).css({
08                    "border": "1px solid red",
09                    "background": "#FFCECE"
10                });
11            }
12            else {
13                $(this).css({
14                    "border": "",
15                    "background": ""
16                });
17            }
18        });
19        if (isValid == false)
20            e.preventDefault();
21        else
22            alert('Thank you for submitting');
23    });
24});​

Get & Set Value in Web control

Get label value:

$('#<%=Label1.ClientID%>').text();
Set label value:

$('#<%=Label1.ClientID%>').text("New Value");
Get Textbox value:
 $('#<%=TextBox1.ClientID%>').val();
Set Textbox value:
 $('#<%=TextBox1.ClientID%>').val("New Value");
Get Dropdown value:
 $('#<%=DropDownList1.ClientID%>').val();
Set Dropdown value:
 $('#<%=DropDownList1.ClientID%>').val("New Value");
Get text of selected item in dropdown:
$('#<%=DropDownList1.ClientID%> option:selected').text();
Get Checkbox Status:
 $('#<%=CheckBox1.ClientID%>').attr('checked');
Check the Checkbox:
 $('#<%=CheckBox1.ClientID%>').attr('checked',true);
Uncheck the Checkbox:
 $('#<%=CheckBox1.ClientID%>').attr('checked',false);
Get Radiobutton Status:
 $('#<%=RadioButton1.ClientID%>').attr('checked');
Check the RadioButton:
 $('#<%=RadioButton1.ClientID%>').attr('checked',true);
Uncheck the RadioButton:
 $('#<%=RadioButton1.ClientID%>').attr('checked',false);
Disable any control:
 $('#<%=TextBox1.ClientID%>').attr('disabled', true);
Enable any control:
 $('#<%=TextBox1.ClientID%>').attr('disabled', false);
Make textbox read only:
view sourceprint?
 $('#<%=TextBox1.ClientID%>').attr('readonly', 'readonly');