views:

57

answers:

1

I have a master page with that code:

    public string CallbackMethod;

    protected void Page_Load(object sender, EventArgs e)
    {
        CallbackMethod = Page.ClientScript.GetCallbackEventReference(this, "message", 
                         "Dodanie", "context", true);
    }

    /other code here/

then, in the View (which is based on that master page) I need to invoke the CallbackMethod string, but the problem is, the framework firstly renders the View, and then invokes the Page_Load method. As the obvious result, the error appears:

the name 'CallbackMethod' does not exist in the current context.

How do I fix this?

+3  A: 

You don't use ASP.NET Page_Load with ASP.NET MVC. You don't use "CallBackMethod" in ASP.NET MVC either. The paradigm is completely different.

It is not an event Driven Paradigm.

If you want to use Ajax, you can use it without invoking anything from the Webforms Framework. Here is an example of how to use Ajax with ASP.NET MVC.

George Stocker
My thoughts exactly - if you're relying on Page_Load in MVC you're doing something wrong
Jaco Pretorius
I started reading a nice post about Ajax + MVC http://www.nikhilk.net/Ajax-MVC.aspx but I don't see where I can get the AjaxController
Tony