Posts

Difference between href="#" and href="javascript:void(0)"

href="" will link to the same page as the one you are currently on, effectively refreshing the page. href="#" will not refresh the page, but using the # will make the screen move to the top of the page (it is the browser effectively looking for an anchor with no name, ). javascript:void(0) will prevent anything happening on the link at all.

Returning Multiple Values in JAVASCRIPT

function myFunction() {   var result = testFunction();    alert(result[0]);//returns "1"    alert(result[1]);//returns "2"    alert(result[2]);//returns "3" } //This function returns multiple values(a,b,c) in the form of array. function  testFunction()  {   var a="1",b="2",c="3";     return [a,b,c] }

Calling Server Side Method Using jQuery/Ajax

With this post I would show how to call server side method from client side. Here we will use jQuery to utilize the Ajax Capabilities which will help us to get/post data to/from server Asynchronously. There are many methods available to perform an async callback to the server. Here I will show a simple example as in how to call a code behind Webmethod. For simplicity I would be calling the code behind method on a Button Click. Here is the code: Aspx markup : 1: <asp:Button ID= "Button1" runat= "server" Text= "Click" /> 2: <br /><br /> 3: <div id= "myDiv" ></div> jQuery : 1: <script src= "http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type= "text/javascript" ></script> 2: <script type = "text/javascript" > 3: $(document).ready(function () { 4: $( '#<%=Button1.ClientID %>' )...

"IN" operator in LINQ

SQL Query using IN operator SELECT Members . Name FROM Members WHERE Members . ID IN ("1,2,3" ) LINQ Query equivalent string [] str = { "1" , "2" }; var list = Members .Where(p=> str.Contains(p.ID)) .Select(X => X);

LINQ To SQL - CASE Statements

Image
Switch functionality can be accomplished by using " Tern ary Operator " The ternary operator takes the "if" statement and turns it into an expression.  Here's an example: The syntax is <condition>  ? <true value> : <false value> Now, let's add a basic case statement.  This will return the text "This is poisonous!" for plants with a 0 in the edible field, and "Okay to eat" otherwise.  By looking at the generated SQL using the debug visualizer, we can see that a CASE statement is in fact being generated. Now the question will come up, "what if I want to have more than just one WHEN and an ELSE".  In other words, how do I add more cases.  Here's the trick: By replacing the "if false" value of the ternary expression with another ternary expression we logically create the same effect as a SQL CASE statement.  Unlike the switch statement, this is an expression, and can be used on the ...

Types of LINQ syntax

There are 2 types of LINQ Syntax: 1.Fluent syntax 2.Query syntax string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" }; IEnumerable<string> query = names.Where (name => name.EndsWith ("y")); query.Dump ("In fluent syntax"); query = from n in names where n.EndsWith ("y") select n; query.Dump ("In query syntax");

Combining interpreted and local queries.

void Main() { // This uses a custom 'Pair' extension method, defined below. IEnumerable<string> q = Customers .Select (c => c.Name.ToUpper()) .Pair() // Local from this point on. .OrderBy (n => n); q.Dump(); } public static class MyExtensions { public static IEnumerable<string> Pair (this IEnumerable<string> source) { string firstHalf = null; foreach (string element in source) if (firstHalf == null) firstHalf = element; else { yield return firstHalf + ", " + element; firstHalf = null; } } }