Tony
Tony

Reputation: 12715

Using the Callback Method on a View in ASP.NET MVC

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?

Upvotes: 0

Views: 1186

Answers (1)

George Stocker
George Stocker

Reputation: 57917

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.

Upvotes: 3

Related Questions