i nomi che ho utilizzato io sono puramente di esempio.
Dipende dal codice che stai facendo.
Se la funzione lato server è un vero e proprio webservice, lo scriptmanager ti crea u proxy javascript che ti permette di richiamare il tuo codice dal client:
[System.Web.Script.Services.ScriptService]
[WebService(Namespace = "
http://xmlforasp.net")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class CustomersService : System.Web.Services.WebService
{
[WebMethod]
public Customer[] GetCustomersByCountry(string country)
{
return Biz.BAL.GetCustomersByCountry(country);
}
}
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/CustomersService.asmx" />
</Services>
</asp:ScriptManager>
function GetCustomerByCountry()
{
var country = $get("txtCountry").value;
<namespacecompleto>.GetCustomersByCountry(country, OnWSRequestComplete);
}
qui la documentazione completa:
http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-web-services
Esite anche la possibilità di utilizzare le PageMethods, che sono dei simil-webService ma costruiti direttamente nel code-behind della pagina aspx.
Sono più facili da creare, se non hai grosse necessità e non hai una struttura complessa del sito.
Devi abilitare le PageMethods, creare un metodo nella pagina con il tag webmethod, richiamarlo da javascript con la parola chiave pagemethods:
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true" />
public partial class ContactUs : System.Web.UI.Page
{
[WebMethod]
public static void SendForm(string name, string email, string message)
{
...
}
function SendForm() {
var name = $get("NameTextBox").value;
var email = $get("EmailTextBox").value;
var message = $get("MessageTextBox").value;
PageMethods.SendForm(name, email, message,
OnSucceeded, OnFailed);
}
function OnSucceeded() {
// Dispaly "thank you."
$get("ContactFieldset").innerHTML = "<p>Thank you!</p>";
}
function OnFailed(error) {
// Alert user to the error.
alert(error.get_message());
}
____________
Ricordati di utilizzare il tasto "Accetta" se i nostri consigli ti sono serviti a risolvere il problema.
È il modo per ringraziare chi ti ha aiutato.