• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

ajax erorr

Hey guys i am trying to do a slide show in my asp master page

and i get this erorr:

The target 'ctl00' for the callback could not be found or did not implement ICallbackEventHandler.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The target 'ctl00' for the callback could not be found or did not implement ICallbackEventHandler.

Source Error:


Line 42:
Line 43:         //Register Ajax client script to client's browsers.  This has to be hard coded.
Line 44:         string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
Line 45:         string callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + "} ;";
Line 46:         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
 
Here my code:

 
<head runat="server">
    <title>Master Page</title>
    <link rel="SHORTCUT ICON" href="http://www.ramcon.jcwebhostza.com/images/logo.ico" />
    <link href="css/StyleSheet.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
    <meta name="google-site-verification" content="jUeh_AsOSwIDTvXB83yaYl2jgdMbCDcqScpADEZZ-Ko" />

    <script type="text/javascript">
        //A timer will be fired in 5 seconds to call getNextImage()
        var c_interval = 5000;
        window.setTimeout("getNextImage()", c_interval);
        
        function getNextImage()
        {
            //Send the request to server with the current image url as the argument
            CallServer(document.getElementById("photo").src, "");
        }
                  
        function ReceiveServerData(rValue)
        {
            //Receive server's response of a string rValue, which is prepared in the server's function
            //GetCallbackResult()
            var wds = rValue.split(";");
            //Assign the transition effect
            document.getElementById("photo").style.filter = wds[1];
            //Preload the image file from server.  When finishing download, imageLoaded function will be called
            //with the img object as the argument                           
            var img  = new Image();
            img.onload = function(){ imageLoaded(this); }
            img.onerror = function(){ imageError(this); }
            img.onabort = function(){ imageError(this); }
            img.src = wds[0];                                            
        }
        
        function imageError(img)
        {
            //If image download errors occur, this function will be called.
            window.setTimeout("getNextImage()", 1000);
        }
        function imageLoaded(img)
        {
            var photo = document.getElementById("photo");   //Find the image control object
            photo.filters[0].apply();                       //Apply the transition effect
            photo.filters[0].play();                        //Play the effect and display the new image
            photo.src = img.src;                            //Assign the image to the image control
            
            window.setTimeout("getNextImage()", c_interval);//Initiate the next request
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div style="display: none">
        <asp:ToolkitScriptManager ID="ToolkitScriptManager" runat="server">
        </asp:ToolkitScriptManager>
    </div>
    <div id="header">
        <table cellpadding="0" cellspacing="0" style="width: 100%; height: 258px;">
            <tr>
                <td class="header_table_lft">
                    &nbsp;
                </td>
                <td style="width: 950px; height: 258px; vertical-align: top;">
                    <table cellpadding="0" cellspacing="0" style="width: 950px; height: 258px;">
                        <tr>
                            <td class="header_table_logo" rowspan="2">
                                &nbsp;
                            </td>
                            <td class="header_table_cnt" colspan="2" valign="top">
                                <img alt="" id="photo" src="~/images/slide/pic_1.jpg" runat="server" width="766"
                                    height="224" style="position: absolute" />
                                <div id="slideshow">
                                </div>
                            </td>
                        </tr>

Open in new window


 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using System.IO;
using System.Data.SqlClient;

public partial class MasterPage : System.Web.UI.MasterPage
{
    string connStr = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
    string m_lastFileName = "none";

    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        using (SqlConnection conn = new SqlConnection(connStr))
        {
            string sql = "Select id, title, parent_id, url from menu ORDER BY id DESC";
            SqlDataAdapter da = new SqlDataAdapter(sql, conn);
            da.Fill(ds);
            da.Dispose();
        }

        ds.DataSetName = "Menus";
        ds.Tables[0].TableName = "menu";
        DataRelation relation = new DataRelation("ParentChild", ds.Tables["menu"].Columns["id"], ds.Tables["menu"].Columns["parent_id"], true);

        relation.Nested = true;
        ds.Relations.Add(relation);

        xmlDataSource.Data = ds.GetXml();

        photo.Src = GetNextImageUrl();

        //Register Ajax client script to client's browsers.  This has to be hard coded.
        string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
        string callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + "} ;";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
    }

    public void RaiseCallbackEvent(string eventArgument)
    {
        m_lastFileName = Path.GetFileName(eventArgument);
    }

    public string GetCallbackResult()
    {
        return GetNextImageUrl() + ";" + GetNextTransition();
    }

    private string GetNextImageUrl()
    {
        string[] files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "images", "*.jpg");
        if (files.Length == 0)
            return string.Empty;

        while (true)
        {
            int n = (int)((files.Length - 1) * (new Random()).NextDouble());
            if (files[n].IndexOf(m_lastFileName) < 0)
            {
                return files[n].Replace(AppDomain.CurrentDomain.BaseDirectory, string.Empty);
            }
        }
    }

    private string GetNextTransition()
    {
        int n = (int)((new Random().NextDouble()) * 5);
        switch (n)
        {
            case 0:
            case 1:
                n = (int)((new Random().NextDouble()) * 22);
                return "revealTrans(duration=2,transition=" + n.ToString() + ")";
            case 2:
            case 3:
                if (Request.Browser.Browser == "IE")
                {
                    n = (int)((new Random().NextDouble()) * 8);
                    switch (n)
                    {
                        case 0:
                            return "progid:DXImageTransform.Microsoft.RandomDissolve()";
                        case 1:
                            return "progid:DXImageTransform.Microsoft.Pixelate(MaxSquare=20, Duration=2, Enabled=false)";
                        case 2:
                            return "progid:DXImageTransform.Microsoft.RadialWipe(wipeStyle='clock')";
                        case 3:
                            return "progid:DXImageTransform.Microsoft.Wheel(spokes=4)";
                        case 4:
                            return "progid:DXImageTransform.Microsoft.Stretch(stretchStyle='spin')";
                        default:
                            return "progid:DXImageTransform.Microsoft.Stretch(stretchStyle='push')";
                    }
                }
                else
                    return "blendTrans(duration=2)";
            default:
                return "blendTrans(duration=2)";
        }
    }
}

Open in new window

0
JCWEBHOST
Asked:
JCWEBHOST
  • 3
1 Solution
 
ivan_vaguninCommented:
Hi! As it is said in error message, you should implement ICallbackEventHandler interface for your page. As I see you have implemented the interface functions, but you must specify that your page implement this interface at class declaration (the interface is "invisible" otherwise):
public partial class MasterPage : System.Web.UI.MasterPage, ICallbackEventHandler
{ ....
0
 
JCWEBHOSTAuthor Commented:
ok thanks i did that, but now i got a run time erorr:

 CallServer(document.getElementById("photo").src, "");

i change my image id to this ctl00_photo

so i can not reffernce it
0
 
ivan_vaguninCommented:
Try this:
CallServer(document.getElementById("<%= photo.ClientID %>").src, "");
0
 
ivan_vaguninCommented:
This happens because asp.net changes client id of control accoring to control tree hierachy when using master page.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now