Hey Guys,
the following is my aspx page
<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title></head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server"EnablePageMethods="true"/>
<div>
<scripttype="text/javascript">
function getme(){
PageMethods.getResults();
}
</script><asp:LabelID="lblText"runat="server"></asp:Label>
<inputtype="button"value="btnVal"onclick="getme();"/></div>
</form></body>
</html>
The following is my code behind
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
publicpartialclass_Default : System.Web.UI.Page{
protectedvoid Page_Load(object sender,EventArgs e){
}
[WebMethod()]publicvoid getResults(){
lblText.Text ="Sridhar";}
}
The Current Version only support static method for Page Methods. So you cannot access the other element of the page.
Modify your page method return a string, then set lblText's value on the client side. This is an example of doing exactly that: http://encosia.com/index.php/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/
No comments:
Post a Comment