 |
|
|
 |
|
 |
Hi,
I have created my application as per the code given in the article. But when i try to run the application it is throwing a javascript run time error "Sys not defined". I have checked all the code but not able to find any such line in the aspx file please do help me as this is very urgent for me.
For you referance i am pasting the aspx and cs code.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<script type="text/javascript" language="javascript">
function CallSum()
{
debugger
var val1=document.getElementById("txtval1").value;
var val2=document.getElementById("txtval2").value;
var lbresult=document.getElementById("lblresult").value;
PageMethods.Sum(val1.value,val2.value,OnCallSumComplete,OnCallSumError,lbresult);
}
function OnCallSumComplete(result,lbresult,Sum)
{
debugger
lbresult.value=result;
}
function OnCallSumError(error,userContext,Sum)
{
debugger
if(error !== null)
{
alert(error.get_message());
}
}
</script>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<br />
<table>
<tr>
<td style="width: 100px">
Val 1</td>
<td style="width: 100px">
<asp:TextBox ID="txtval1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
Val 2</td>
<td style="width: 100px">
<asp:TextBox ID="txtval2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
Result</td>
<td style="width: 100px">
<asp:Label ID="lblresult" runat="server"></asp:Label></td>
</tr>
<tr>
<td style="width: 100px; height: 26px">
</td>
<td style="width: 100px; height: 26px">
<input id="Button1" type="button" value="Calculate" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
Server Code:
[System.Web.Services.WebMethod]
public static int Sum(int arg1, int arg2)
{
//On server side we can do anything, like we can access the Session.
//We can do database access operation. Without postback.
try
{
return arg1 + arg2;
}
catch (Exception ex)
{
throw ex;
}
}
Prasenjit Basu_Chennai
|
|
|
|
 |
|
 |
Hi,
First i wanna say it was great article.
But i when i try in my web page i got error said "PageMethods is undefined".
here's my code :
<script type="text/javascript" language="javascript">
function CountBack(myDiv)
{
// my code here
PageMethods.SignOut();
}
</script>
code behind :
[System.Web.Services.WebMethod]
public static void SignOut()
{
FormsAuthentication.SignOut();
}
i already add ScriptManager with EnablePageMethods = "true" and call my javascript at body onload. Is there anything i must set to call the PageMethods property ?
Thank You
Regards,
Tomi
|
|
|
|
 |
|
 |
No detailed comments were available
|
|
|
|
 |
|
 |
i m using asp.net 1.1
how i can do this in asp.net 1.1
|
|
|
|
 |
|
 |
Can you please post the sam code in vb also.
i cannot fint the equivalentvb code of the following script
..how to make a webmethod in vb.net
[System.Web.Services.WebMethod]
public static int Sum(int arg1, int arg2)
{
}
|
|
|
|
 |
|
 |
<System.Web.Services.WebMethod()> _
Public Function GetString(ByVal value As String) As String
That should do the trick.
Br
|
|
|
|
 |
|
 |
If i remove [System.Web.Services.WebMethod] , then application throws an error PageMethods Not found?
Can u pls provide reason for this.
|
|
|
|
 |
|
 |
We can run the PageMethods by javascript. To create a PageMethod we need to add [System.Web.Services.WebMethod] attribute at function level. By this this function treat as a PageMethod.
Thanks
Paresh
|
|
|
|
 |
|
 |
In my case it is not calling server side function, do I need to set anything in web.config in order to call static webMethod.
Thanks in advance
|
|
|
|
 |
|
 |
1. Set EnablePageMethods="true" in ScriptManager object.
2. Server Side function should be public and static and add [System.Web.Services.WebMethod] attribute.
Try again. all the best
|
|
|
|
 |
|
 |
I have already done both.
I have put break point on the server side function but it doesn't stop there and when I debug javascript I found that it calls OnCallSumError function which should be called on faliure of serverside function.
|
|
|
|
 |
|
 |
Please send me the code. I will check it.
|
|
|
|
 |
|
 |
Did you find a solution to this, I am having the same problem. I get 'There was a problem processing the request.'
|
|
|
|
 |
|
 |
No, I am not getting this problem. So unable to find it's solution.
|
|
|
|
 |
|
 |
Hi,
Congratulation for the great job. I have a question. It's possible call a non static method on the code behind file? I have trying but the code is only reached when you define a static method.
cheers.
Lisandro Pacheco
|
|
|
|
 |
|
 |
Only static methods are allowed to make Web Method. Reason behind this is system can not access controls in this methods. You can access only session and the parameters which are passed in this method. So methods are only static. By this if you want to access any control then compile time error will come.
Thanks
Paresh
|
|
|
|
 |
|
 |
can we use this in usercontrol ?
|
|
|
|
 |
|
 |
yes we can use this in usercontrol, but that usercontol should be used at any web form.
|
|
|
|
 |
|
 |
You should expand a little more, add more text than just code comments
only two letters away from being an asset
|
|
|
|
 |