Callback in 2.0 renders an "Object Expected" Error

Last post 03-26-2006 7:00 AM by NC01. 4 replies.

Sort Posts:

  • Callback in 2.0 renders an "Object Expected" Error

    03-24-2006, 10:06 PM
    • Member
      45 point Member
    • wotmman
    • Member since 07-10-2005, 3:08 PM
    • Posts 9

    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 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:

    Line: 57

    Char: 1

    Error: Object Expected

    Code: 0

  • Re: Callback in 2.0 renders an "Object Expected" Error

    03-25-2006, 8:19 AM
    • All-Star
      76,195 point All-Star
    • NC01
    • Member since 08-26-2005, 3:33 PM
    • Posts 14,194
    • TrustedFriends-MVPs

    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...

     

  • Re: Callback in 2.0 renders an "Object Expected" Error

    03-25-2006, 9:08 AM
    • Member
      45 point Member
    • wotmman
    • Member since 07-10-2005, 3:08 PM
    • Posts 9

    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.

  • Re: Callback in 2.0 renders an "Object Expected" Error

    03-25-2006, 11:07 AM
    • Member
      45 point Member
    • wotmman
    • Member since 07-10-2005, 3:08 PM
    • Posts 9

    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.

  • Re: Callback in 2.0 renders an "Object Expected" Error

    03-26-2006, 7:00 AM
    • All-Star
      76,195 point All-Star
    • NC01
    • Member since 08-26-2005, 3:33 PM
    • Posts 14,194
    • TrustedFriends-MVPs

    Glad you got it. Can't believe that MS would have a broken sample, but I've seen it before.

    NC...

     

Page 1 of 1 (5 items)