Partial page update with Script call backs
Plz refer to page 344-345 of the book.
My aspx code is as follows:
************
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Java_Callback.aspx.cs"
Inherits="Java_Callback" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" >
function ShowResult(result, context)
{
alert(result);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtValue" runat="server" />
<input id="btnSubmit" runat="server" type="button" value="Calc" />
</form>
</body>
</html>
********************
the corresponding code behind file is as per below:
***********
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class Java_Callback : System.Web.UI.Page, ICallbackEventHandler
{
string callbackResult = "";
protected void Page_Load(object sender, EventArgs e)
{
string callbackRef = this.ClientScript.GetCallbackEventReference(this,
"window.document.getElementByID('txtValue').value" , "ShowResult", null);
btnSubmit.Attributes.Add("onclick", callbackRef);
}
public string GetCallbackResult()
{
return callbackResult;
}
public void RaiseCallbackEvent(string eventArgument)
{
callbackResult = (int.Parse(eventArgument) * 2).ToString();
}
}
***************
When I view the aspx page in browser, type a number in textbox and click on the button, I get error "Microsoft JScript runtime error: Object doesn't support this property or method", with highlighted line ( in VS) "onclick="WebForm_DoCallback('__Page',window.docum ent.getElementByID('txtValue').value,ShowResult,nu ll,null,false)"
Grateful if anyone could please point me to source of the error and how to rectify.
Big Thanks !!
|