Saturday, September 17, 2016

What is Jquery

JQuery is a Javascript library which is used extensively for client side validation and manipulation of DOM elements. It is a light weight, cross browser compatible and is a repository of many reusable Javascript functions.
the features of jQuery
  • DOM element selections functions
  • DOM traversal and modification
  • Events
  • CSS manipulation
  • Effects and animations
  • Ajax
  • Extensibility
  • Utilities - such as browser version and the each function.
  • JavaScript Plugins 

Wednesday, August 3, 2016

What is MVC?

MVC is architecture pattern. It’s divided in main 3 sections:
  1. Model
  2. View
  3. Controller

      Model: The Model represents a set of classes that describe the business logic and provides the data to view.
View:  View is responsible for look and feel. It is only responsible for displaying the data that is received from the controller as the result.
Controller: controller is responsible for take the user request and process the user's data with the help of Model and passing the results back to the View.

What are Action methods in ASP.NET MVC?

All the public methods of a Controller class are called Action methods.
Action methods is responsible for accept the request from user and with the help of Model and passing the results back to the View. 
Action method with the following restrictions:
  1. Action method must be public. It cannot be private or protected
  2. Action method cannot be overloaded
  3. Action method cannot be a static method.



Action method are return ActionResult.
If you want to a public action methods  are not accessible from the URL. You decorate with NONACTION attribute.
E.g.

[NonAction]
public void AddressInfo(){
// some code inside here
}
[NonAction]
public ActionResult Address(){
// some code inside here
return View();
}

Wednesday, September 24, 2014

Difference Between Var  & dynamic data type

VAR
  • Introduced in C# 3.0
  • Statically typed – This means the type of variable declared is decided by the compiler at compile time.
  • Need to initialize at the time of declaration.
    e.g., var str="string Type";
    Looking at the value assigned to the variable str, the compiler will treat the variable str as string.
  • Errors are caught at compile time.
    Since the compiler knows about the type and the methods and properties of the type at the compile time itself.
  • Visual Studio shows intellisense since the type of variable assigned is known to compiler.
  • e.g., var Object2;

    will  throw a compile error since the variable is not initialized. The compiler needs that this variable should be initialized so that it can infer a type from the value.
  • e.g. var obj1=1;
    will compile
    var obj1="string Type";

    will throw error since the compiler has already decided that the type of obj1 is System.Int32 when the value 1 was assigned to it. Now assigning a string value to it violates the type safety.

Dynamic

  • Introduced in C# 4.0
  • Dynamically typed - This means the type of variable declared is decided by the compiler at runtime time.
  • No need to initialize at the time of declaration.
    e.g., dynamic strValue; 
    strValue=”String Type”; //Works fine and compiles
    strValue=100; //Works fine and compiles
  • Errors are caught at runtime
    Since the compiler comes to about the type and the methods and properties of the type at the run time
  • Intellisense is not available since the type and its related methods and properties can be known at run time only
    • e.g., dynamic object2; 
      will compile;
    • e.g., dynamic object2; 
      will compile and run
      dynamic object2="String Type";
  • will compile and run since the compiler creates the type for obj1 as System.Int32 and then recreates the type as string when the value “I am a string” was assigned to it.

    This code will work fine. 

Tuesday, October 2, 2012

Jquery: How to use index()

.index()- returns an integer indicating the position of the passed element relative to the original collection.
-1 means selector or element not found.

 Three way to use index()
1.index()

2..index( selector )
 selector A selector representing a jQuery collection in which to look for an element.
3..index( element )
element The DOM element or first element within the jQuery object to look for.

 Note : Start index is 0(Zero).

more detail- http://api.jquery.com/index

Example
<html>
<head>
  <style>div { font-weight: bold; color: #090; }</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <ul>
  <li id="foo">foo</li>
  <li id="bar">bar</li>
  <li id="baz">baz</li>
</ul>
<div></div>
 <script> 
    var listItem = $('#bar');
    $('div').html( 'Index: ' + $('li').index(listItem) );
 </script>
</body>
</html>
 
Output Demo
  • foo
  • bar
  • baz
Index: 1

Wednesday, August 29, 2012

JQuery:preventDefault() method will do.


e.preventDefault() is the key method, to disable the default operations to proceed further. We first stop the event from further bubbling up to other parent controls and put any custom logic.

@"e" is a event.


Example:
$('#<%=textbox.ClientID%>').bind('cut copy paste',
function (e) {
e.preventDefault();
alert("Cut / Copy / Paste are not allowed.");

});

Tuesday, August 28, 2012

MVC: set Default value in Html.TextboxFor Helper In Asp.Net MVC 2

Html.TextBoxFor in MVC 2 doesn't allow the setting of the value property using the object html attributes.
syntax - 
<%= Html.TextBoxFor(model => model.city, new { maxlength = "40" })%>

If you need to set a default value on a textbox field, you need to use the old 

syntax - 
<%= Html.TextBox("city", "New Delhi", new { maxlength = "40" })%>

Thursday, March 1, 2012

Generic function call


 public class clsGeneric
    {
        public void show<T>(T value)
        {
            Type t = typeof(T);
            Console.WriteLine(t.Name + ":" + value);
        }
    }


 class Program
    {
         static void Main(string[] args)
        {
             clsGeneric ng;
            ng = new  clsGeneric();
            int a = 10;
            ng.show(a);
            string b = "SS";
            ng.show(b);

            Console.WriteLine("Press any key to close........");
            Console.ReadKey();
        }
    }

OUTPUT
----------------------------
Int32:10
String:SS
Press any key to close........



use global variable with same name of Local variable


 public class Demo1
    {
        int a = 10;
        public  void ff()
        {
            int a = 11;
            Console.WriteLine("a={0}", this.a);
        }


   class Program
    {
        static void Main(string[] args)
        {
              Demo1 ng = new   Demo1();
             ng.ff();

            Console.WriteLine("Press any key to close........");
            Console.ReadKey();

        }
}


Output:
-----------------------------------
a=10
Press any key to close........
-----------------------------------

Tuesday, February 14, 2012

Bind generic dictionary collection to combobox


Dictionary<string, string>  DicSearch;
DicSearch = new Dictionary<string, string>();
DicSearch.Add("1", "Mohit");
DicSearch.Add("2", "Agrawal");

cboSearch.DataSource  = new BindingSource(DicSearch, null);
cboSearch.DisplayMember = "value";
cboSearch.ValueMember = "key";
DicSearch = null;

Hash Table in C#

 The Hashtable is a non-generic collection and used to store the key/value pairs based on the hash code of the key. Key will be used to acce...