javascript - Datalist Delete Command Event implementation using Page Methods -


i have datalist , update panel in page. after implementation, checked response talking long time after using update panels...here study material. have delete command event in datalist , works find in above mentioned case. trying implement delete command using page methods. idea how that?

i want find hidden controls in event , have delete record in `database. highly appreciated.

rest services

the full application can downloaded from:

http://sdrv.ms/ljjz1k

this sample uses rest services in asp.net (the same concepts can applied mvc application)

the clearer advantage when using rest services vs page methods, testability.

i guide step step configure service:

you need following references:

  • system.web.servicemodel.dll
  • system.web.servicemodel.activation.dll
  • system.web.servicemodel.web.dll

nuget packages:

jquery plugins:

service info

[servicecontract] public interface imyservice {     [operationcontract]     [webinvoke(         responseformat = webmessageformat.json,          requestformat = webmessageformat.json,         uritemplate = "/deletefromservice",         method = "delete")]     void delete(int id); }  [aspnetcompatibilityrequirements(requirementsmode = aspnetcompatibilityrequirementsmode.allowed)] public class myservice : imyservice {     public void delete(int id)     {         // delete product         // simulate long process         thread.sleep(5000);     } } 

in global.asax

void application_start(object sender, eventargs e) {     // code runs on application startup     routetable.routes.ignore("{resource}.axd/{*pathinfo}");     routetable.routes.add(new serviceroute("",       new webservicehostfactory(),       typeof(myservice)));  } 

in web.config

  <system.servicemodel>     <servicehostingenvironment aspnetcompatibilityenabled="true" />     <standardendpoints>       <webhttpendpoint>         <standardendpoint name="" helpenabled="true"           automaticformatselectionenabled="true" />       </webhttpendpoint>     </standardendpoints>   </system.servicemodel> 

register scripts (they can registered in master page)

<script type="text/javascript" src="scripts/jquery-1.7.2.min.js" language="javascript" ></script> <script language="javascript" type="text/javascript" src="scripts/jquery.blockui.1.33.js"></script> 

in asp.net content page (in sample, using master page)

<asp:content id="bodycontent" runat="server" contentplaceholderid="maincontent"> <input type="button" value="delete" id="mybutton" /> </asp:content>  <asp:content id="headercontent" runat="server" contentplaceholderid="headcontent">     <script type="text/javascript" language="javascript">         function deletefromservice() {             if (!confirm("are sure want delete?")) {                 return;             }             $.blockui();             $.ajax({                 cache: false,                 type: "delete",                 async: true,                 url: "/deletefromservice",                 data: "3", // id delete                 contenttype: "application/json",                 datatype: "json",                 success: function () {                     $(document).ajaxstop($.unblockui);                      alert("done");                 },                 error: function (xhr) {                     $(document).ajaxstop($.unblockui);                      alert(xhr.responsetext);                 }             });         }         jquery().ready(function () {                         $("#mybutton").click(deletefromservice);         });     </script> </asp:content> 

and that’s it, ajax commands easy way =)


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -