Jack @ ASP.NET

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘quot quot’

Call web service via jQuery in asp.net

step 1. Add Web service, and you must add a [System.Web.Script.Services.ScriptService] to the service class

(in webservice.asmx.cs file)

   1: /// <summary>

   2: /// Summary description for WebService1

   3: /// </summary>

   4: [WebService(Namespace = "http://tempuri.org/")]

   5: [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

   6: [System.ComponentModel.ToolboxItem(false)]

   7: // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 

   8: [System.Web.Script.Services.ScriptService]

   9: public class WebService1 : System.Web.Services.WebService

  10: {

  11:     [WebMethod]

  12:     public string DeleteProduct(string id)

  13:     {

  14:         Thread.Sleep(800);

  15:         return "Hello World22: " + id;

  16:     }

  17: }

step 2. call webservice in aspx via jQuery

(in head of the page)

   1: <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

   2: <script type="text/javascript">

   3:     $(function () {

   4:         $('a').click(function () {

   5:             deleteProduct(111);

   6:         }); // end of  $('a').click(function () {

   7:  

   8:     });     // end of $(function () {

   9:  

  10:  

  11:  

  12:     function deleteProduct(id) {

  13:         $.ajax({

  14:             type: "POST",

  15:             url: "WebService1.asmx/DeleteProduct",

  16:             data: "{id: '" + id.toString() + "'}",

  17:             contentType: "application/json; charset=utf-8",

  18:             dataType: "json",

  19:             success: function (msg) {

  20:                 AjaxSucceeded(msg);

  21:             },

  22:             error: AjaxFailed

  23:         });

  24:     }

  25:     function AjaxSucceeded(result) {

  26:         alert(result.d);

  27:     }

  28:     function AjaxFailed(result) {

  29:         alert(result.status + ' - ' + result.statusText);

  30:     }  

  31: </script>

TODO Comments in Visual Studio

Using TODO

imageTODO comments allow you to tell Visual Studio to maintain a central list of tasks, which it reads from many different places in your code. The Task List is a panel or floating window in Visual Studio that will display all the TODO comments in your project. To open the list, go to View menu -> Task List.

Some example TODO comments

You probably have a lot of code that needs a lot of work. If you don’t, then you need to write code that needs a lot of work. Here are some examples of TODO lines that Visual Studio 2008 will notice and put into its special Task Pane.

//todo: your task 1
//TODO: your task 2
// Todo your task 3

Description of example. This will appear in your tasks pane as a separate task. Note that you have some flexibility with these tokens. The strings "todo", "TODO", and "TODO" all work equally well—Visual Studio’s parser gives you a little bit of freedom.

jQuery hoverImage plugin

   1: (function($) {

   2:     $.fn.extend({

   3:         hoverImage: function(options) {

   4:             var defaults = { src: "-hover", preload: true, replaceEnd: "" };

   5:             options = $.extend(defaults, options);

   6:  

   7:             var append = options.src.indexOf(".") == -1;

   8:  

   9:             var splitter;

  10:             if (append) {

  11:                 splitter = options.replaceEnd + ".";

  12:             }

  13:  

  14:             return this.each(function() {

  15:                 var obj = $(this);

  16:                 var img = obj.is("[src]") ? obj : obj.children("[src]:first").eq(0);

  17:  

  18:                 if (!img.is("[src]")) {

  19:                     return true;

  20:                 }

  21:  

  22:                 var oSrc = img.attr("src");

  23:                 img.data("oSrc", oSrc);

  24:  

  25:                 var hSrc = options.src;

  26:                 if (append) {

  27:                     hSrc = oSrc.split(splitter).join(hSrc + ".");

  28:                 }

  29:                 

  30:                 img.data("hSrc", hSrc);

  31:  

  32:                 if (options.preload) {

  33:                     new Image().src = hSrc;

  34:                 }

  35:  

  36:                 obj.hover(function() { img.attr("src", img.data("hSrc")); },

  37:                           function() { img.attr("src", img.data("oSrc")); });

  38:             });

  39:         }

  40:     });

  41: })(jQuery);

Here’s a sample of html in which the plug-in is used.

   1: <html xmlns="http://www.w3.org/1999/xhtml">

   2: <head runat="server">

   3:     <title>hoverImage test page</title>

   4:     <script src="/ClientScript/jquery-1.3.2.min.js" type="text/javascript"></script>
   1:  

   2:     <script src="/ClientScript/jquery.hoverImage.js" type="text/javascript">

   1: </script>

   2:  

   3:     <script type="text/javascript">

   4:         $(function() {

   5:             $(".standardImage").hoverImage({replaceEnd: "-standard"});

   6:             $(".hoverImage").hoverImage();

   7:         });

   8:     

</script>

   5: </head>

   6: <body>

   7:     <form id="form1" runat="server">

   8:     <div>

   9:         <img class="standardImage" src="Imgs/button-standard.gif" />

  10:         <img class="hoverImage" src="Imgs/button.gif" />

  11:         <a class="hoverImage" href="#" style="display:block; width:100%;border:solid 1px black;">

  12:             <img src="Imgs/button.gif" />

  13:         </a>

  14:     </div>

  15:     </form>

  16: </body>

  17: </html>

Happy 2010~~