Saturday, December 28, 2013

JSON Simple Example using AJAX and JQUERY

Introduction:

Hi, today we going to learn JSON concept using AJAX with jquery in c# coding.
Others basic example of my previous post would be a beneficial for you like OOPS concept, and for more search the topic with the search text in the top of the page.

In my example I have used png format so that you type yourself and learn in a better way.

Description:

Json is a Javascript Object Notation, in which the data can be transferred efficiently with light weight and  subset of javascript programming language.
Now a days for webservices we use json format for fast processing of data.

AJAX   is the art of exchanging data with a server, and updating parts of a web page - without reloading the whole page.

In my example i am using jquery source file from the server " http://code.jquery.com/jquery-1.8.2.js ", you can download and set in your file as browser will show error on offline.

Example:

Create the table in your database as like below, I am using toad sql server for creating in my local host.




Now, create the design code in the aspx page or htm page.







after that now add jquery json format as given below between the script tag as given below,




now in the code behind page, add the following 




Now done, If you like my post show it by liking my post thank you!

here you can view the video of sample program given above,





Monday, December 23, 2013

Extendable textbox using jQuery

Extendable textbox using jQuery (Set Maximum length for multiline textbox)

Introduction:

Here we going to see how using the jquery we can extend the multiline textbox length.
For more search on asp.net search it through the search box provided above.

Description:

We know that the jQuery is the small pre written function using javascript, here I am using jquery1.9.1.js file as a script source.
To use a jquery source file, 
we need to declare the script type and source to give the path of the file.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js">
</script>
Above we declare the js source path now we need to open a script tag within that we have to gice our condition function supported by the source js file.

<script type="text/javascript">
here the source file function will be entered
</script>

$(function() 
{
 $('#txt_example').keypress(function(e) {
 var txt = $(this).val();
 if (txt.length > 50) {
 e.preventDefault();
 }
 });
 });
                                                              })

Now on the asp.net page put some asp control.
like
<asp:Textbox ID="txt_example" TextMode="MultiLine" runat="server" ></asp:TextBox>

Now whenever you type in the text box it will stretch upto its maximum value.
For any other clarification comment below.

Tuesday, December 3, 2013

STRING AND STRING BUILDER

STRING AND STRING BUILDER  (C#)

Introduction

               The string and stringbuilder in c# using asp.net and their differences.

Description

          In my previous posts we have seen Oops conceptsSql Data ReaderAdo Objects  here we going to see about the string and stringbuilder and their difference.

String

          The string is a data type object which replaces its value if we use insert, update or append. That means each time it will create a separate memory space for its value in the memory to hold a new value.

Example:

StringBuilder 

             In the stringbuilder the insert, update and append can be performed with the first instance without creating   instance each time.

Example:

                 
Difference between string and stringbuilder 

String
1. Low performance than stringbuilder as it creates instance on every instance.   
2. In string it uses "+"  operator for append.
3. String requires System namespace.

Stringbuilder
1. High performance than string as it doesn't creates instance on every instance.   
2. In stringbuilder it uses append for adding.
3. String requires System.Text namespace.


Normally for small usages we use string
The string builder can be used for the special cases like, when we press print button on the ticket page the response page will be as per the given input that type of requirement we use stringbuilder.

******************************************************

Thursday, November 28, 2013

C# OOPS CONCEPTS

FIRST READ EXAMPLE FOR OOPS CONCEPTS

Before going into the OOPS concepts I would like to give you one scenario based on that the oops concept will be well defined for you!

For example if you attending an interview, the company will get your resume and also they will give you a format of paper to be filled out. On the form it may contains the information you gave along with your resume and also other information required for the company.

here the company has some format and they not updating the information with a single format rather than they getting xerox copy of that and providing to everyone and receiving back the information they need.

                  From the above point of view, the single format of classified application form is a CLASS and number of xerox is said to be an OBJECT in the object oriented language programming.

                       If we need any alteration in the form we do not delete the entire form and create a new one, rather than we get the maximum contents of the previous form and create a new form with necessary columns in the new form, thus by inheriting the value and contents of the previous form is said to be a Inheritance.

                       In this scenario the people filling out the form cannot able to see the other form, is called Abstraction. Hiding of irrelevant data.

                     If the same form is distributed with various names for various different sections is called Polymorphism.
                    Take the above example as a reference only. Whenever you are about to learn any new technologies do not think too much at the initial as you will be in a hurry stage and many thing will confuse you take little time to learn day by day and you will understand once your known things are joined and give you the result.
Most importantly do not think, why it is use rather than think how it should be use!!!



Now we going to see what a oops language in .net environment, 

Class:

          A Class is a collection of object. A main template.

Objects:


         An object contains member attributes and member functions.

      Syntax:

       class  form
    {
           form objectname = new form();     
     }
  In asp.net the each time you drag any controls it actually creates a object.




Encapsulation:

Encapsulation is a process of binding the data members and member functions.

Example for encapsulation is class. A class can contain data structures and methods.
Consider the following class

public class Aperture
{
public Aperture ()
{
}
protected double height;
protected double width;
protected double thickness;
public double get volume()
{
Double volume=height * width * thickness;
if (volume<0)
return 0;
return volume;
}
}

In this example we encapsulate some data such as height, width, thickness and method Get Volume. Other methods or objects can interact with this object through methods that have public access modifier.


Abstraction , C# has five access Specifiers

Public -- Accessible outside the class through object reference.

Private -- Accessible inside the class only through member functions.

Protected -- Just like private but Accessible in derived classes also through member 
functions.

Internal -- Visible inside the assembly. Accessible through objects.

Protected Internal -- Visible inside the assembly through objects and in derived classes outside the assembly through member functions.


Inheritance:


Using System;
Public class BaseClass
{
    Public BaseClass ()
    {
        Console.WriteLine ("Base Class Constructor executed");
    }
                                 
    Public void Write ()
    {
        Console.WriteLine ("Write method in Base Class executed");
    }
}
                                 
Public class ChildClassBaseClass
{
                                 
    Public ChildClass ()
    {
        Console.WriteLine("Child Class Constructor executed");
    }
   
    Public static void Main ()
    {
        ChildClass CC = new ChildClass ();
        CC.Write ();
    }
}

Note: Classes can inherit from multiple interfaces at the same time. 
Interview Question: How can you implement multiple inheritance in C#? Ans : Using Interfaces. We will talk about interfaces in our later article.


Polymorphism:

When a message can be processed in different ways is called polymorphism. Polymorphism means many forms.
Polymorphism is one of the fundamental concepts of OOP.
Polymorphism provides following features: 

  • It allows you to invoke methods of derived class through base class reference during runtime.
  • It has the ability for classes to provide different implementations of methods that are called through the same name. 
  • Polymorphism is of two types:
    1. Compile time polymorphism/Overloading
    2. Runtime polymorphism/Overriding
    Compile Time Polymorphism
    Compile time polymorphism is method and operators overloading. It is also called early binding.
    In method overloading method performs the different task at the different input parameters.
    Runtime Time Polymorphism

  • Runtime time polymorphism is done using inheritance and virtual functions. Method overriding is called runtime polymorphism. It is also called late binding.
    When overriding a method, you change the behavior of the method for the derived class.  Overloadinga method simply involves having another method with the same prototype.
    Caution: Don't confused method overloading with method overriding, they are different, unrelated concepts. But they sound similar.
      In very simple manner u use the same method name for doing a addition function with different parameters is called overloading we use the same method name for different function is called overriding.

All the best.............................................................................









Monday, November 25, 2013

SQLDATAREADER

SQLDATAREADER

Introduction

The sqldatareader is the object we use in the ado.net for accepting or retrieving the row of a table from the database.
The syntax is,

sqldatareader sqlDr = sqlcommandtype.executereader;

the sqldatareader will read the value row by row and we need to open the connection and close the connection.
As we use the void return type in function call, here we need to specify the return type there are three types of return value,
ExecuteNonQuey
ExecuteScalar 
ExecuteReader

The execute reader is used to get the single value from the data table.

The execute scalar is used for the single row retrieval query like aggregate function().

The ExecuteNonQuery will not return the value like void.

example, if we need to get the value of a data cell from one data table,
        sqlconnection con = new sqlconnection("connection string");

        con.open();
        sqlcommand cmd = new sqlcommand("select * from tablename where empid =                                                                                                                                               '100'",con);
        sqldatareader dr = cmd.executereader();
        
        if(dr.read)                                               //if data reader have any data or record  
        {
                label.text =Convert.ToString( dr[0]["columnName"] );                  
         }

        con.Close();



****************************************************************************************************************