0

I created an app stand alone and it works with my callback. I am trying to integrate it into a larger app and am having some issues.

My stand-alone app callback code:

public partial class Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{

    protected void Page_Load(object sender, EventArgs e)
    {
        //unimportant specific code

        //Get the Page's ClientScript and assign it to a ClientScriptManger
        ClientScriptManager cm = Page.ClientScript;

        //Generate the callback reference
        string cbReference = cm.GetCallbackEventReference(this, "arg", "HandleResult", "");

        //Build the callback script block
        string cbScript = "function CallServer(arg, context){" + cbReference + ";}";

        //Register the block
        cm.RegisterClientScriptBlock(this.GetType(), "CallServer", cbScript, true);

    }


    public void RaiseCallbackEvent(string eventArgument)
    {

        //unimportant specific code

        //This method will be called by the Client; Do your business logic here
        //The parameter "eventArgument" is actually the paramenter "arg" of CallServer(arg, context)

        GetCallbackResult(); //trigger callback
    }

    public string GetCallbackResult()
    {

        //unimportant specific code

        return callbackMessage;
    }

    //more specific unimportant stuff

}

Why can I not just add the class to my larger app like this:

public class My_App_ItemViewer : abstractItemViewer, System.Web.UI.Page, System.Web.UI.ICallbackEventHandler

In visual studio, I get an error that says 'page' interface name expected.

In the callback code itself, I get an error where it references to ClientScript saying 'cannot access static property 'clientSript' in nonStatic context'.

I do not really understand these terms... I do not have a CS degree or anything, so if anyone could explain this, that would be great (perhaps even the greatest), thanks!

yoyo
  • 79
  • 3
  • 11

1 Answers1

2

C# does not support multiple inheritance, so you cannot do the following line:

public class My_App_ItemViewer : abstractItemViewer, System.Web.UI.Page, System.Web.UI.ICallbackEventHandler

Just to clarify, the way you have written the above, the C# compiler thinks that abstractItemViewer is a class that you are trying to inherit from. The compiler then sees the "System.Web.UI.Page" part and is looking for an interface named that, it does not find it, because System.Web.UI.Page is a class and not an interface; thus error.

You can, however, implement multiple interfaces, so you could do the following:

public class My_App_ItemViewer : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler, IAbstractItemViewer
Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
  • I think I follow you, but in my case, 'abstractItemViewer' is a separate class. Applying your knowledge, It appears the error is that c# is looking at abstractItemViewer as an interface and not a class. Further, it looks like you can only have one 'inherited class' (this is probably what you are saying with multiple inheritance. So how can I get around this? Make another class "mycallback" and inherit my_app_viewer? – yoyo Jun 21 '13 at 14:46
  • So, I just went to my abstract class and added the 'system.web.ui.page' inheritance and it at least compiled. I'm doing some more testing to see if it will actually work... – yoyo Jun 21 '13 at 14:58
  • Now the issue is that the actual callback javascript scripts are showing up in the page source code. Is this because I have separated the System.Web.UI.Page and System.Web.UI.ICallbackEventHandler to two different pages? – yoyo Jun 21 '13 at 15:33
  • Looks like "page_load" is not firing. I found [link](http://stackoverflow.com/questions/2737092/how-to-execute-page-load-in-pages-base-class) but when I put `public My_App_ItemViewer() { this.Load += new EventHandler(this.Page_Load); }` I get an error that says my_app_itemviewer already defined... – yoyo Jun 21 '13 at 16:01
  • Sorry, I was away working on something for awhile, just now got back to your responses. For your first reply, your abstractItemViewer is a class and an ASP.NET page is also a class, which is the reason you are not able to inherit from both. Is abstractItemViewer a page or a standalone class? What is the purpose of the abstractItemViewer? – Karl Anderson Jun 21 '13 at 18:42
  • It might help to explain from a broader point of view what you are trying to accomplish. – Karl Anderson Jun 21 '13 at 18:43