1

I have following layout, related to the one i am describing in this question

<ext:Viewport runat="server">
  <Items>
    <ext:Panel Region="North" runat="server" ID="TopBar" />
    <ext:Panel Region="West" runat="server" ID="Nav" >
       <Items>
          <ext:Button runat="server" ID="loaderComponentFooBar">
             <DirectEvents>
                <Click OnEvent="loadFooBar" />
             </DirectEvents>
          </ext:Button>
          //Some more Buttons each with his own loader Function in Code-Behind
       </Items>
    </ext:Panel>
    <ext:Panel runat="server" Region="center" ID="MainPanel" />
  </Items>
</ext:Viewport>

on Button-Click i now want to load my View @ "/Foo/Bar/" to the MainPanel

How can i achieve this in CodeBehind?

I already tried:

public void loadFooBar(object sender, DirectEventArgs e)
{
   MainPanel.Loader.Url = "/Foo/Bar/"; //Throws null reference Exception

   MainPanel.Loader.Url = "~/Foo/Bar/"; // same as above

   MainPanel.Loader.GetUrlByRoute("Foo/Bar/"); //again the same

   MainPanel.Loader.LoadContent("/Foo/Bar/");

   //and after each of these attempts except the last went:
   MainPanel.Loader.Mode = LoadMode.Frame;
   MainPanel.Loader.LoadMask.ShowMask = false;
   MainPanel.Loader.LoadContent();
}

Just by the way, i am using aspx-web-application views

1 Answer 1

4

I think you should not use a page's code behind for DirectEvents' handlers. It is going out of the MVC concept. You should refer a controller's actions.

Here is an example.

Example View

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>Ext.Net.MVC v2 Example</title>
</head>
<body>
    <ext:ResourceManager runat="server" />

    <ext:Viewport runat="server" Layout="BorderLayout">
        <Items>
            <ext:Panel runat="server" Region="West" Width="100">
                <Items>
                    <ext:Button 
                        runat="server" 
                        Text="Load View 1" 
                        DirectClickUrl=<%# Url.Action("LoadView1") %>
                        AutoDataBind="true" />

                    <ext:Button 
                        runat="server" 
                        Text="Load View 2" 
                        DirectClickUrl=<%#Url.Action("LoadView2") %>
                        AutoDataBind="true" />
                </Items>
            </ext:Panel>

            <ext:Panel ID="MainPanel" runat="server" Region="Center">
                <Loader runat="server" Mode="Frame" AutoLoad="false">
                    <LoadMask ShowMask="true" />
                </Loader>
            </ext:Panel>
        </Items>
    </ext:Viewport>
</body>
</html>

Example Controller

using System.Web.Mvc;
using Ext.Net;
using Ext.Net.MVC;

namespace Work2MVC.Controllers
{
    public class AspxController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult View1()
        {
            return View();
        }

        public ActionResult View2()
        {
            return View();
        }

        public ActionResult LoadView1()
        {
            Panel p = X.GetCmp<Panel>("MainPanel");
            p.LoadContent(Url.Action("View1"));

            return this.Direct();
        }

        public ActionResult LoadView2()
        {
            Panel p = X.GetCmp<Panel>("MainPanel");
            p.LoadContent(Url.Action("View2"));

            return this.Direct();
        }
    }
}

Also you can initiate a load request on client side via JavaScript. Then you avoid an additional request.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.