ASP.NET de async işlem yapabilmek için JQueryden faydalanmanız gerekiyor.
Bunu 2 yöntem ile yapmak mümkün
1. ScriptManager
2. JQuery methodları ile
2. methoda daha dogal geldiginden işlemlerimizi onunla gerçekleştiricez.
a) İlk olarak .cs tarafında methodumuzu yazalım :
[System.Web.Services.WebMethod]
public static string Kaydet(string a,string b)
{
string result = "OK : " + a + " - ";
return result;
}
b) Şimdi JQuery kütüphaneleri eklediginizi düşünerek hemen HTML kontrolün çağıracagı JS methoda oluşturalım :
function Kaydetsene(a,b) {
$.ajax({
type: "POST",
url: "sevkiyatci.aspx/Kaydet",
data: "{a:'aaaa',b:'bb'}",
contentType: "application/json;",
dataType: "json",
success: function(response) { alert("OK : "+ response.d);},
failure: function(response) { alert("HATA : "+ response.d);}
});
}
c) Son alarakda methodu control üzerindeki bi event ile çagırıyoruz
OnClick='<%# Eval("Fat_No","Kaydetsene(\"{0}\",\"2\");") %>'
OnClick='<%# "Kaydetsene(\"" + Eval("Fat_No") + "\",\"2\");" %>'
//-----digerleri------
var k = $('[id$=lbl_kim]').attr('title');
var params = "{'Kimden':'"+k+"'}";
$('#okun').text('0');
setTimeout("GetMSJsayisi();", 10000);
// digerleri iki - eger farklı ise
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
//----------------- dropdownlist
JavaScript ile:
var e = document.getElementById("elementId");
var value = e.options[e.selectedIndex].value;
var text = e.options[e.selectedIndex].text;
jQuery ile:
$("#elementId :selected").text(); // The text content of the selected option
$("#elementId").val(); // The value of the selected option