I've been trying to just create a simple function to utlize the new Callback feature of 2.0. I've copied the code right out of the book. I did find a few simple typos in the book (such as Sub with end fuction instead of end sub), otherwise, I've followed
all the steps and still get an error code when I try to run the javascript with ICallbackeventhandler. I'm attaching my aspx file and vb file for anyone who might be able to find why I cannot get this to run. Thanks in advance for your help:
Class companytour_Default2
Inherits System.Web.UI.Page
Implements System.Web.UI.ICallbackEventHandler
Dim _callbackResult
As String =
Nothing
Protected Sub Page_Load(ByVal sender
As Object,
ByVal e As System.EventArgs)
Handles Me.Load
Dim cbReference
As String = Page.ClientScript.GetCallbackEventReference(Me,
"arg", "GetServerTime",
"context")
Dim cbScript
As String =
"function UseCallback(arg, context)" &
"{" & cbReference &
"; }"
Page.ClientScript.RegisterClientScriptBlock(
Me.GetType(),
"UseCallback", cbScript,
True)
End Sub
Public Sub RaiseCallbackEvent(ByVal eventArgument
As String)
Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
_callbackResult =
Date.Now.ToString
End Sub
Public Function GetCallbackResult()
As String
Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
Return _callbackResult
End Function
End
Class
This is the basic sample in the book Professional ASP.NET 2.0 by Wrox Publishing. It seems conceptually very simple. When I run the page, it displays fine. However, when I click the textbox, nothing
happens and an Errror displays on the bottom of the page. When I click on the error details I get the following:
Thanks for the links. I've read through them and tried a few things but still could not get it to work. (interesting to see the micorsoft link shows a sample of a sub statement that has a Return line in it. This error for me and says you cannont Return
a value from this type of routine)
As for the line of error on View Source, it appears this is the line being referrenced:
function UseCallback(arg, context){WebForm_DoCallback('__Page',arg,GetServerTime,context,null,false); }// -->
The object Expected error must refer to one of these compoonents, I'm just not sure which one.
Never mind all. My fault. After hours of research and digging through the vb code, i realized I was missing a "t" in my input onclick= call to the function calling getime instead of gettime.
wotmman
Member
45 Points
9 Posts
Callback in 2.0 renders an "Object Expected" Error
Mar 25, 2006 02:06 AM|LINK
I've been trying to just create a simple function to utlize the new Callback feature of 2.0. I've copied the code right out of the book. I did find a few simple typos in the book (such as Sub with end fuction instead of end sub), otherwise, I've followed all the steps and still get an error code when I try to run the javascript with ICallbackeventhandler. I'm attaching my aspx file and vb file for anyone who might be able to find why I cannot get this to run. Thanks in advance for your help:
aspx:
<%
@ Page Language="VB" AutoEventWireup="true" CodeFile="time.aspx.vb" Inherits="companytour_Default2" EnableEventValidation="true"%><!
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> <script type="text/javascript"> function gettime(){UseCallback();
}
function GetServerTime(txtTextbox1, context){document.forms[0].Textbox1.value = Textbox1;
}
</
script></
head><
body> <form id="form1" runat="server"> <div> <asp:textbox ID="Textbox1" runat="server"></asp:textbox> <p /> <input id="btnStartClock" type="button" OnClick="getime()" Value="Start" /> </div></form></
body></
html># NOW THE VB CODE #
Partial
Class companytour_Default2 Inherits System.Web.UI.Page Implements System.Web.UI.ICallbackEventHandler Dim _callbackResult As String = Nothing Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim cbReference As String = Page.ClientScript.GetCallbackEventReference(Me, "arg", "GetServerTime", "context") Dim cbScript As String = "function UseCallback(arg, context)" & "{" & cbReference & "; }"Page.ClientScript.RegisterClientScriptBlock(
Me.GetType(), "UseCallback", cbScript, True) End Sub Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent_callbackResult =
Date.Now.ToString End Sub Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult Return _callbackResult End FunctionEnd
ClassThis is the basic sample in the book Professional ASP.NET 2.0 by Wrox Publishing. It seems conceptually very simple. When I run the page, it displays fine. However, when I click the textbox, nothing happens and an Errror displays on the bottom of the page. When I click on the error details I get the following:
Line: 57
Char: 1
Error: Object Expected
Code: 0
NC01
All-Star
82559 Points
15430 Posts
MVP
Re: Callback in 2.0 renders an "Object Expected" Error
Mar 25, 2006 12:19 PM|LINK
Do a View Source in your browser and see what that line points to. Also, here are a couple of links that might help you out.
http://msdn2.microsoft.com/en-us/library/ms178208.aspx
http://west-wind.com/weblog/posts/2694.aspx
NC...
wotmman
Member
45 Points
9 Posts
Re: Callback in 2.0 renders an "Object Expected" Error
Mar 25, 2006 01:08 PM|LINK
Thanks for the links. I've read through them and tried a few things but still could not get it to work. (interesting to see the micorsoft link shows a sample of a sub statement that has a Return line in it. This error for me and says you cannont Return a value from this type of routine)
As for the line of error on View Source, it appears this is the line being referrenced:
function UseCallback(arg, context){WebForm_DoCallback('__Page',arg,GetServerTime,context,null,false); }// -->
The object Expected error must refer to one of these compoonents, I'm just not sure which one.
wotmman
Member
45 Points
9 Posts
Re: Callback in 2.0 renders an "Object Expected" Error
Mar 25, 2006 03:07 PM|LINK
Never mind all. My fault. After hours of research and digging through the vb code, i realized I was missing a "t" in my input onclick= call to the function calling getime instead of gettime.
Sorry.
NC01
All-Star
82559 Points
15430 Posts
MVP
Re: Callback in 2.0 renders an "Object Expected" Error
Mar 26, 2006 11:00 AM|LINK
Glad you got it. Can't believe that MS would have a broken sample, but I've seen it before.
NC...