Thursday, August 23, 2018

JQuery Interview Questions and answers

1.What are the basic selectors in jQuery?

Following are the basic selectors in jQuery:

A)Element ID
    A ID available the DOM Using ID we can axxess the control in JQuery.

using JQuery
$("#EmpId")

B)CSS Name
     A  class name will be available in the DOM usinf class name we can access this in JQuery.

using JQuery
$(".Menu")

C)Tag Name
    A tag name available in the DOM. For example $('a') selects anchor tags in the DOM.

using JQuery
$("a")

Monday, August 20, 2018

Free source code Version Control Systems

SVN
Subversion is the most used version control used in worldwide. Most open-source projects use Subversion as a repository because other larger projects, such as SourceForge, Apache, Python, Ruby and many others, use it as well.Because of its popularity, there are many versions and IDEs available.

Git
Git is the new fast-rising version control systems. Initially developed by Linux kernel creator Linus Torvalds, Git has recently  taken the Web development community by storm. Now Git has quickly emerged as a preferred version control system in nowadays.
 Thanks to its distributed form of control without any master copy of the software, many open
 source projects and system administrators prefer Git. Let us have a look at the key pros and cons of this system.

Sunday, August 19, 2018

Required Field Validator not Working For DropDownList asp.net

You need to set the value as 0 in the InitialValue of validator or change the value of first item of DropDown.



cssclass="required" display="dynamic" errormessage="*" setfocusonerror="true"

InitialValue="0">

Wednesday, August 15, 2018

State Management techniques In ASP.NET MVC


State Management In ASP.NET MVC.
 We all know that HTTP is a state less protocol. Hence, If we want to pass data from one page to another page or even on multiple  
 visits of the same page, then we need to use the State management techniques to store user specific data.  
 Here, i am going discuss various techniques to pass the data from a Controller to View or Controller to Controller.  
 ASP.NET MVC doesn’t support ViewState or Server controllers.  
 To achieve state management in ASP.NET MVC, there are four basic ways which are given as following.  
 1.ViewData  
 2.ViewBag  
 3.TempData  
 4.Sessions  
 1.ViewData  
 ViewData is used to pass the data from Controller to View.It is derived from ViewDataDictionary class, it requires typecasting for complex datatypes   
 and it requires a null check to void exceptions.  
 Controller  
 public ActionResult Index()   
     {   
       ViewData["CurrTime"] = DateTime.Now;   
       return View();   
     }   
 HTML Index.cshtml Code  
 @ViewData["CurrentTime"];  
 2.ViewBag  
 ViewBag is also used to pass data from Controller to View. It is a dynamic property which uses the Dynamic feature of C# 4.0. And, the  
 Dynamic keyword internally uses reflection.  
 Controller Code  
 public ActionResult Index()   
     {   
       ViewBag.CurrTime = DateTime.Now;   
       return View();   
     }   
 html Index.cshtml code  
 @ViewBag.CurrentTime  
 3.TempData  
 TempData is used to pass the data from Action to Action or Controller to Controller, and then to View. It keeps the information for single HTTP Request.  
 It is derived from TemDataDictionary and along with this, it requires typecasting for complex data types and it requires a null check to void exceptions.  
 Controller Code  
 public ActionResult Index()   
     {   
       TempData["CurrTime"] = DateTime.Now;   
       return View();   
     }   
 Html Index.cshtml code  
 @TempData["CurrTime"];  
 4.Session  
 If you want to store the data and maintain it for multiple requests, then use session variables.  
 Controller Code  
 public ActionResult Index()   
     {   
 Session["CurrTime"] = DateTime.Now;   
       return View();   
     }   
 Html Index.cshtml Code  
 @Session["CurrentTime"];  

How to Upload Files in ASP.NET MVC

 Upload Files In ASP.NET MVC
Here i am going to explain File Upload example in ASP.Net MVC  
 Below code is quite limited and simple functionality for single file upload, and it will work in any browser.  
 Before uploading the file, we will check whether Directory exists if not exist then the Directory will be created.  
 View  
 View consists of an HTML form containing the submite button, which open a select file dialog, and Submit, which sends the chosen file to  
 the server in a POST request.  
 <html>  
 <head>  
   <meta name="viewport" content="width=device-width"/>  
   <title>Index</title>  
 </head>  
 <body>  
   <div>  
     @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))  
     {  
       <span>Select File:</span>  
       <input type="file" name="postedFile"/>  
       <hr/>  
       <input type="submit" value="Upload"/>  
       <br/>  
       <span style="color:green">@ViewBag.Message</span>  
     }  
   </div>  
 </body>  
 </html>  
 Controller  
 public class HomeController : Controller  
 {  
   // GET: Home  
   [HttpGet]  
   public ActionResult Index()  
   {  
     return View();  
   }   
   [HttpPost]  
   public ActionResult Index(HttpPostedFileBase postedFile)  
   {  
     if (postedFile != null)  
     {  
       string path = Server.MapPath("~/Upload/");  
       if (!Directory.Exists(path))  
       {  
         Directory.CreateDirectory(path);  
       }   
       postedFile.SaveAs(path + Path.GetFileName(postedFile.FileName));  
       ViewBag.Message = "File uploaded successfully.";  
     }   
     return View();  
   }  
 }  

JQ GRID in ASP.NET MVC 4 using Razor

 JQ GRID Using MVC with Razor View Engine in ASP.NET MVC 4  
 Friends,Here i am going to explain how to use jqgrid in asp.net mvc4 with rzor view engine.JQGrid is one of the most flexible and stable
 gird you can find in the current tech market. It’s free to use. Here i am going to write basic step to do where data will come from 
database to show in JQgrid.  
 Following are step by step sequence to create the JQGRID.  
 1.Create a new ASP.NET MVC 4 Web Project  
 2.Select Empty template with Razor   
 4.Right Click on the Controller and Add new Controller  
 5.Copy and paste the below code in the controller as fllowing  
 using System;  
 using System.Collections.Generic;  
 using System.Web;  
 using System.Web.Mvc;  
 using System.Data;  
 using System.Data.SqlClient;  
 using System.Configuration;  
 using JQGridExample.Models;  
 namespace JQGridExample.Controllers  
 {  
   public class EMPLOYEEController : Controller  
   {  
     public ActionResult EmpDetails()  
     {  
       return View();  
     }  
     public JsonResult getEmpDetails()  
     {  
       List<Employee> items = new List<Employee>();  
       items = getData();  
       var a = Json(items, JsonRequestBehavior.AllowGet);  
       a.MaxJsonLength = int.MaxValue;  
       return a;  
     }  
     public List<Employee> getEmpData()  
     {  
       string connString = ConfigurationManager.ConnectionStrings["Mycon"].ConnectionString;  
       SqlConnection conn = new SqlConnection(connString);  
       SqlCommand cmd = new SqlCommand();  
       cmd.CommandTimeout = 6000;  
       cmd.CommandText = "select * from employee";  
       cmd.Connection = conn;  
       conn.Open();  
       DataTable dataTable = new DataTable();  
       SqlDataAdapter da = new SqlDataAdapter(cmd);  
       da.Fill(dataTable);  
       conn.Close();  
       da.Dispose();  
       List<Employee> items = new List<Employee>();  
       foreach (DataRow row in dataTable.Rows)  
       {  
         items.Add(new MEmployee  
         {  
           Id = row["ID"].ToString(),  
           Name = row["Name"].ToString(),  
           Gender = row["Gender"].ToString(),  
           Contact = row["Contact"].ToString(),  
           Address = row["Address"].ToString(),  
           State = row["State"].ToString(),  
                          Country = row["Country"].ToString()  
         });  
       }  
       return items;  
     }  
   }  
 }  
 6.Add new class to the Model folder and paste the below code in the Model.  
 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Web;  
 namespace JQGridExample.Models  
 {  
   public class Employee  
   {  
     public string Id { get; set; }  
     public string NAME { get; set; }  
     public string Name { get; set; }  
     public string Gender { get; set; }  
     public string Contact { get; set; }  
     public string Address { get; set; }  
           public string State { get; set; }  
           public string Country { get; set; }  
   }  
 }  
 8. Right Click on the Controller and Add the View ,name should be EmpDetails  
 9. Add below code to the created EmpDetails view  
 @{  
   ViewBag.Title = "JQGrid Esample";  
 }  
 <html>  
 <head>  
   <title>My First JQGrid Example</title>  
 <script src="~/Scripts/jquery-1.11.0.min.js"></script>  
 <link href="yourlocalpath/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css" rel="stylesheet" />  
 <script src="yourlocalpath/jqgrid/4.6.0/jquery.jqGrid.min.js"></script>  
 <script src="yourlocalpath/jqgrid/4.6.0/i18n/grid.locale-en.js"></script>  
 <script src="yourlocalpath/jqgrid/4.6.0/jquery.jqGrid.min.js"></script>  
 <link href="yourlocalpath/jqgrid/4.6.0/css/ui.jqgrid.css" rel="stylesheet" />  
   <style type="text/css">  
     .ui-jqgrid .ui-widget-header {  
       background-color: #336699;  
       background-image: none;  
       color: white;  
     }  
     .ui-jqgrid .ui-jqgrid-labels th.ui-th-column {  
       background-color: #FFCC66;  
       background-image: none;  
       color: #336699;  
       height: 30px;  
       font-weight: bold;  
     }  
   </style>  
   <script type="text/javascript">  
     $(function () {  
       $("#myEmpGrid").jqGrid({  
         url: '@Url.Action("getEmpDetails")',  
         datatype: 'json',  
         mytype: 'get',  
         colNames: ['Id','Name', 'Gender', 'Contact', 'Address', 'State','Country'],  
         colModel: [  
 { name:'Id', width:'35px' },  
 { name:'Name', width:'160px' },  
 { name:'GENDER' },  
 { name:'Gender' },  
 { name:'Address' },  
 { name:'State'},  
 { name:'Country'}  
               ],  
         pager: $('#myPager'),  
         rowNum: 5,  
         sortname: 'ID',  
         gridview: true,  
         sortorder: 'desc',  
         loadonce: true,  
         rowList: [5, 10, 20, 50],  
         width: 600,  
         height: 110,  
         viewrecords: true,  
         caption: 'Emp details in JQ Grid'  
       });  
     });  
   </script>  
 </head>  
 <body>  
   <div>  
     <table id="myEmpGrid"></table>  
     <div id="myPager"></div>  
   </div>  
 </body>  
 </html>  
 Run your application and test