PDA

View Full Version : فراخوانی یک فانکشن در وب متود



mojahed
یک شنبه 15 خرداد 1390, 08:46 صبح
با سلام دوستان
من میخواهم در یک وب متود یک فانکشن را صدا بزنم کسی میتواند راهنمایی کند.

hesamsalehnamadi
یک شنبه 15 خرداد 1390, 20:29 عصر
مراحل زیر این کار رو انجام میده امیدوارم بتونه مشکلت رو حل کنه

1: نوشتن تابع جاوا اسکریپت


<script type="text/javascript">
function CallCodeBehind(argID)
{
PageMethods.CallCodeBehind(argID,onSucceeded,onFai led);
}
function onSucceeded(result,userContext,methodName)
{
$get(''resultDiv'').innerHTML=result;
}

function onFailed(error,userContext,methodName)
{
alert("An error occurred");
}
</script>


2: صفحه aspx



<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>

<input type="button" name="button" onclick="CallCodeBehind(''argument value'')" value="click me" />
<div id="resultDiv"></div>



3: قسمت code behind




[System.Web.Services.WebMethod()]
public static string CallCodeBehind(String argID)
{
return "Code Behind method is called from Client Side Javascript";
}