[CLOSED] Universal PartialViewResult Problem

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Universal PartialViewResult Problem

    Hi vladimir

    To simplify my project, I made my own version of a partialviewresult. The problem is, like in a thread before, to activate ID's that are aleady rendered.


    The Interesting Part is:

    myControllerContext.HttpContext.Response.Write("if(!Ext.get('" + myXControl.ClientID + "')){" + myXControl.ToScript(this.RenderMode, this.ContainerId ?? "={Ext.getBody()}", this.Index, true) + "} else { Ext.get('" + myXControl.ClientID + "').activate;}");
    How can I check if a ID is there - and if yes - activate/show/bring to front - regardless if it's a tab or something else...

    Thanks




     
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Web;
    using System.Web.Compilation;
    using System.Web.Mvc;
    using System.Web.UI;
    using Ext.Net;
    using Ext.Net.Utilities;
    namespace BPM.LIB.MVC
    {
        public class PartialViewResult : ViewResultBase
        {
            public string ContainerId { get; set; }
            public int Index { get; set; }
            public IDMode IDMode { get; set; }
            private RenderMode RenderMode { get; set; }
            public PartialViewResult()
            {
            }
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="myModel"></param>
            public PartialViewResult(object myModel)
            {
                this.ViewData.Model = myModel;
            }
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="containerId">Destination Element for RenderMode.AddTo</param>
            public PartialViewResult(string containerId)
            {
                this.ContainerId = containerId;
            }
            public PartialViewResult(object myModel, string myContainerId)
            {
                this.ContainerId = myContainerId;
                this.ViewData.Model = myModel;
            }
            public override void ExecuteResult(ControllerContext myControllerContext)
            {
                try
                {
                    ViewName = myControllerContext.RouteData.GetRequiredString("action");
                    View = this.ViewEngineCollection.FindPartialView(myControllerContext, this.ViewName).View;
                    PartialViewPage myPartialViewPage = new PartialViewPage
                    {
                        ViewData = new ViewDataDictionary(ViewData),
                        ViewContext = new ViewContext(myControllerContext, View, ViewData, TempData, myControllerContext.HttpContext.Response.Output)
                    };
       
                    ResourceManager myResourceManager = new ResourceManager()
                    {
                        RenderScripts = ResourceLocationType.None,
                        RenderStyles = ResourceLocationType.None,
                        IDMode = this.IDMode
                    };
                    myPartialViewPage.Controls.Add(myResourceManager);
                
                    ViewUserControl myViewUserControl = (ViewUserControl)myPartialViewPage.LoadControl(((WebFormView)View).ViewPath);
                    myViewUserControl.ViewData = ViewData;
                    myPartialViewPage.Controls.Add(myViewUserControl);
                    XControl myXControl = Ext.Net.Utilities.ControlUtils.FindControl<XControl>(myViewUserControl);
                    myPartialViewPage.InitHelpers();
                    
                    if (View is IDisposable)
                        ((IDisposable)View).Dispose();
                    this.RenderMode = string.IsNullOrEmpty(this.ContainerId) ? RenderMode.RenderTo : this.Index > 0 ? RenderMode.InsertTo : RenderMode.AddTo;
                    myControllerContext.HttpContext.Response.Write("if(!Ext.get('" + myXControl.ClientID + "')){" + myXControl.ToScript(this.RenderMode, this.ContainerId ?? "={Ext.getBody()}", this.Index, true) + "} else { Ext.get('" + myXControl.ClientID + "').activate;}");
                }
                catch(Exception myException)
                {
                    throw(myException);
                }
            }
            protected override ViewEngineResult FindView(ControllerContext context)
            {
                throw new NotImplementedException();
            }
        }
    }
    Last edited by Daniil; Dec 31, 2010 at 6:26 PM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    I managed to rework the oneliner mentoined at the top:

     
    myControllerContext.HttpContext.Response.Write("if(!Ext.get('" + myXControl.ClientID + "')){" + myXControl.ToScript(this.RenderMode, this.ContainerId ?? "={Ext.getBody()}", this.Index, true) + "} else { " + myXControl.ClientID + ".show();Ext.get('" + myXControl.ClientID+ "').frame();}");

    I think that should be part of the toolkit. The code above is really ugly :cool::cool:
  3. #3
    Quote Originally Posted by tiramisu View Post
    How can I check if a ID is there - and if yes - activate/show/bring to front - regardless if it's a tab or something
    Hi,

    I'm pretty use you won't avoid switch() { } of if() {} instructions...

    To determine a type of control I would suggest you to use .getXType() method:
    http://dev.sencha.com/deploy/dev/doc...ember=getXType

    Instead of Ext.get(id) you could use Ext.getCmp(id) to retrieve a component.

    Also I would suggest you to define a function on client side and :
    myControllerContext.HttpContext.Response.Write("myFunction('"+ myXControl.ClientID + "')");
  4. #4
    Hi daniil

    I adressed this post directly to vladimir, because he was also creating that functionality in this : http://forums.ext.net/showthread.php...sal+controller

    Basicly its JavaScriptResult coming back from the partialviewresult. But I need generic functions to handle windows/tabs show/recration/bring to front etc.

    Regards
  5. #5
    Ok, I also interested what Vladimir will tell us:)
  6. #6
    Dear vladimir

    Have you seen I have a special question for you. :cool:

    Best regards, Flavio
  7. #7
    Hi,

    Sorry, I missed your topic.

    Well, I suggest to check control existence on the clisnt side before request (if control exists then activate it else make request and render it)
    But I like your idea about overrding default functionality during rendering (now the widget always destroyed before rendring). I guess we have to add some js callback which will be called if control with the same id exists, in that call back you can do anything (destroy, activate and etc)
    I think we will create feature request
  8. #8
    The Feature Request ticket has been created.
    https://extnet.lighthouseapp.com/pro...already-exists
  9. #9
    Hi

    Basicly I think it should be possible do that on the client.

    - Multiple windows/tabpanels allowed: No Id is set
    - Single windows/tabpanels: Id must be set accordnigly to the URI (Example: AdministrationClientIndex for AREA-ControllerAction)

    The code below shows my testsample. The problem is the "ctl01_" string... were come that from?

     
    <script type="text/javascript">
    function load(myUrl, myContainerId) 
    {
    var myId = "ctl01_" + myUrl.replace(/\//g, '');
    
    if (!Ext.getCmp(myId)) 
    {
    Ext.Ajax.request({url: myUrl,method: "GET",params: { myContainerId: myContainerId },success: function (response) { eval(response.responseText); }})
    }
    else 
    {
    Ext.getCmp(myId).show();
    Ext.get(myId).frame();
    }
    }
    </script>
    Best regards, Flavio
  10. #10
    Hi,

    The problem is the "ctl01_" string... were come that from?
    If a widget is placed inside control (including UserControl and Master pages) which implement INamingContainer then its ClientID will be complex (will be composed from parents ids)

    From the MSDN documentation:

    "Any control that implements this interface creates a new namespace in which
    all child control ID attributes are guaranteed to be unique within an entire
    application. The marker provided by this interface allows unique naming of
    the dynamically generated server control instances within the Web server
    controls that support data binding. These controls include the Repeater,
    DataGrid, DataList, ListBox, CheckBoxList, HtmlSelect, and RadioButtonList
    controls."

    Basically, this interface causes the ASP.NET runtime to do it's job relative to control naming. It is a "marker" interface, meaning that some piece of code, e.g., the ASP.NET runtime, will use its presence to take some action.

    You can override ClientID generation behaviour, set IDMode="Explicit" for required widget and ID will equal ClientID always
Page 1 of 2 12 LastLast

Similar Threads

  1. Problem with GMapPanel in MVC2 using PartialViewResult
    By tiramisu in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Nov 23, 2010, 7:56 AM
  2. [CLOSED] Universal controller call in MVC
    By tiramisu in forum 1.x Legacy Premium Help
    Replies: 21
    Last Post: Oct 05, 2010, 9:16 AM
  3. [CLOSED] Refresh problem with PartialViewResult
    By Stefanaccio in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 02, 2010, 6:19 AM
  4. [CLOSED] [1.0] Portal as a 'universal' droptarget
    By betamax in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 16, 2010, 3:51 PM
  5. [CLOSED] PartialViewResult Problem
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jan 27, 2010, 11:15 AM

Tags for this Thread

Posting Permissions