开发者

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

开发者 https://www.devze.com 2022-12-24 13:44 出处:网络
I have a master page with that code: public strin开发者_StackOverflow社区g CallbackMethod; protected void Page_Load(object sender, EventArgs e)

I have a master page with that code:

    public strin开发者_StackOverflow社区g 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消