17 February 2013

9 February 2013

Setting the Default Page or Route in MVC application

Setting the Default Page or Route in MVC application


For convenience, we are going to tell MVC that requests to the / URL for our application should be
directed to the Index action method of the Product controller. To do this, open the Global.asax file and 
find the RegisterRoutes method. In this method, there is a call to routes.MapRoute. Change the value 
assigned to the controller property from Default to Product,





Setting the Controller for the Default Route
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Product", action = "Index", id = UrlParameter.Optional }
)




19 January 2013

Assign System.DBNull.Value in SqlParam value instead of 0 using Ternary operator



Assign System.DBNull.Value in SqlParam value instead of 0 using Ternary operator

  int i = 0;
           
  SqlParameter[] SqlParam = null;
  SqlParam = new SqlParameter[1];
  SqlCommand SqlCmd = new SqlCommand();

 SqlParam[0] = new SqlParameter("@SectionCode", SqlDbType.VarChar, 50);
 SqlParam[0].Value = i == 0 ? (object)System.DBNull.Value : i;



3 January 2013

Javascript Confirm button ok and cancel

Javascript Confirm button ok and cancel

var r=confirm("Press a button");
if (r==true)
  {
  x="You pressed OK!";
  }
else
  {
  x="You pressed Cancel!";
  }



18 December 2012

Click the button using Javascript


Click the button using Javascript 

document.getElementById("btnSearch").click();



Javascript Empty validation in Asp.net


Javascript Empty validation

function CheckEmpty() {

           try {
               if (document.getElementById("txtClientNumber").value.trim() == "") {
                   alert("Must enter a Client Number");
                   return false;
               }
           }
           catch (e) {
           }
       }
     

calling javascript from server side
btnAdd.Attributes.Add("onclick", "return CheckEmpty();")



Implementing OAuth validation in a Web API

 I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...