Posts

Showing posts from October, 2011

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);