?
Solved

ajax erorr

Posted on 2011-10-10
4
Medium Priority
?
376 Views
Last Modified: 2012-05-12
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
Comment
Question by:JCWEBHOST
  • 3
4 Comments
 
LVL 18

Accepted Solution

by:
ivan_vagunin earned 2000 total points
ID: 36940943
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
 

Author Comment

by:JCWEBHOST
ID: 36940960
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
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 36941527
Try this:
CallServer(document.getElementById("<%= photo.ClientID %>").src, "");
0
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 36941588
This happens because asp.net changes client id of control accoring to control tree hierachy when using master page.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question