Injecting javascript before PartialViewResult script executed?

  1. #1

    Injecting javascript before PartialViewResult script executed?

    Hi,

    I have a partial view which is requested & loaded into a modal window.

    Following is the action method which generates the partial view:

    public Ext.Net.MVC.PartialViewResult GetPartialView()
    {
    	return new Ext.Net.MVC.PartialViewResult { Model = ...., ViewName = "MyPartialView" };
    }
    After GetPartialView() is called via ajax request, necessary scripts are generated and sent back to the client.

    The executing script looks like this:

    {script:"Ext.net.ResourceMgr.registerIcon([\"TextListBullets\",\"Add\"]);Ext.onReady(function(){Ext.create(\"Ext.window.Window\",{height:400,hidden..... bla bla}
    Question:

    How can i inject my own custom code somewhere in this generated javascript block?

    My purpose is to dynamically load some external javascript files which are needed in the partial view.

    I dont want to statically include script references in every main view i use this partial view. I want to gain some kind of automatization by loading js files when they are needed.
  2. #2
    Please see the following sample
    http://mvc.ext.net/#/Dynamic_Partial_Rendering/Add_Tab/

    It loads css file registered in partial view, the same way you can load js file
    
    @{    MvcResourceManager.RegisterGlobalStyle(Url.Content("~/Areas/Dynamic_Partial_Rendering/Content/Tab.css"));}
  3. #3
    Perfect. That was exactly what i needed!

    What will this method do if it is called multiple times?

    Will it duplicate / override ? Or it checks to see if it has already loaded the file before?
  4. #4
    Resource loading is intiated on the client side (via javascript), if resource was loaded already then request will not be initiated
  5. #5
    Hello:

    Is it possible to inject some dynamic JavaScript code instead of registering a global script? For instance, if I want to run
    alert('Some message');
    before the components in the PartialView are created. Or after...

    Thank you
    Last edited by Daniil; May 30, 2015 at 3:05 PM. Reason: Please use [VAR] tags
  6. #6
    Maybe, this?

    public ActionResult AddTab(string containerId)
    {
        X.Js.AddScript("alert('Before');");
    
        var result = new Ext.Net.MVC.PartialViewResult
        {
            ViewName = "Tab",
            ContainerId = containerId,
            RenderMode = RenderMode.AddTo
        };
    
        this.GetCmp<TabPanel>(containerId).SetLastTabAsActive();
    
        X.Js.AddScript("alert('After');");
    
        return result;
    }
    The code snippet is related to this example:
    http://mvc2.ext.net/#/Dynamic_Partial_Rendering/Add_Tab

Similar Threads

  1. Replies: 14
    Last Post: Mar 14, 2013, 5:56 PM
  2. [CLOSED] IE Process Bar still shows even the function executed successfully
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 18, 2010, 3:56 PM
  3. Replies: 4
    Last Post: Jul 09, 2009, 3:47 PM
  4. [CLOSED] Simple Question: Add Script to ScriptManager via Ext Javascript.
    By Immobilmente in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 12, 2009, 4:06 AM
  5. [CLOSED] which Ext.onReady gets executed first?
    By pkellner in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 15, 2008, 3:40 PM

Tags for this Thread

Posting Permissions