[CLOSED] [1.0] MVC and Scripts

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] [1.0] MVC and Scripts

    Hello vladimir,

    Just wanted to bring it to your attention, not sure if anything can be done, just give me a no if that's the case ... but the following fails. I know why, because we are evaluating all of the javascript as a single line ... but hey just want to know if there is a way around it [Smile]

    Index.aspx:

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Example</title>
        <script type="text/javascript">
            function LoadContent() {
                Ext.Ajax.request( {
                    params: {
                        containerId: 'Panel1'
                    },
                    scripts: true,
                    success: function(r) {
                        eval(r.responseText);
                    },
                    url: '/Example/Example'
                } );
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Panel ID="Panel1" runat="server"
            Height="250"
            Layout="Fit"
            Title="Example"
            Width="500">
            <Buttons>
                <ext:Button ID="Button1" runat="server" Text="Load">
                    <Listeners>
                        <Click Fn="LoadContent" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="Button2" runat="server" Text="Clear">
                    <Listeners>
                        <Click Handler="#{Panel1}.removeAll();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:Panel>
    </body>
    </html>
    Example.ascx:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
    <%@ Import Namespace="Suite.Web" %>
    <script type="text/javascript">
        var myExample = function() {
            alert('Hello World');
        }
        myExample();
    </script>
    
    <ext:TextField ID="Example" runat="server" />
    Also, would you happen to know why a button directevent (click) success property would not be able to see myExample ? I keep getting myExample is undefined with the following:

    <ext:Button ...>
        <Listeners>
            <Click ... Success="myExample()" />
        </Listeners>
    </ext:Button>
    Cheers,
  2. #2

    RE: [CLOSED] [1.0] MVC and Scripts

    Weird, the following works in IE8 and Chrome but not FF3.5

    Example.ascx:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
    <script type="text/javascript" language="javascript">
        function myExample()
        {
            alert('Hello World');
        }
    </script>
    <ext:TextField ID="Example" runat="server" />
    <ext:Button runat="server" Text="Test">
        <DirectEvents>
            <Click Url="/Example/ ..." Success="myExample()">
                <ExtraParams>
                    <ext:Parameter Name="ContainerId" Value="Word" Mode="Value" />
                </ExtraParams>
            </Click>
        </DirectEvents>
    </ext:Button>
    FF keeps saying that myExample is not defined :(

    Cheers,
    Timothy
  3. #3

    RE: [CLOSED] [1.0] MVC and Scripts

    Hi,

    1. Example from first post. You missed semicolumn after function declaration otherwise a js error occurs (please note that script is evulated as one line)
    var myExample = function() {alert('Hello World');}; //<-- here is must be semicolumn

    2. Example from second post works correctly for me under IE8 and FF 3.5.8 (please ensure that you have no js erros when load partial view)
  4. #4

    RE: [CLOSED] [1.0] MVC and Scripts

    Hello vladimir,

    Thanks for point #1 I'll keep that one as solved.

    As for point #2 I'm still receiving "myExample is undefined" in Firebug

    ExampleController.cs:

    public class ExampleController : System.Web.Mvc.Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        
    
        public ActionResult Example(string containerId)
        {
            var result = PartialExtView();
    
            result.ContainerId = containerId;
    
            return result;
        }
    }
    Index.aspx:

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Example</title>
        <script type="text/javascript">
            function LoadContent() {
                Ext.Ajax.request( {
                    params: {
                        containerId: 'Panel1'
                    },
                    scripts: true,
                    success: function(r) {
                        eval(r.responseText);
                    },
                    url: '/Example/Example'
                } );
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Panel ID="Panel1" runat="server"
            Height="250"
            Layout="Fit"
            Title="Example"
            Width="500">
            <Buttons>
                <ext:Button ID="Button1" runat="server" Text="Load">
                    <Listeners>
                        <Click Fn="LoadContent" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="Button2" runat="server" Text="Clear">
                    <Listeners>
                        <Click Handler="#{Panel1}.removeAll();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:Panel>
    </body>
    </html>
    Example.ascx:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
    <script type="text/javascript" language="javascript">
        function myExample()
        {
            alert('Hello World');
        };
    </script>
    
    <ext:TextField ID="Example" runat="server" />
    
    <ext:Button runat="server" Text="Test">
        <Listeners>
            <Click Handler="myExample()" />
        </Listeners>
    </ext:Button>
    Can you confirm this example works on your end in FF 3.5.8?

    Cheers,
    Timothy
  5. #5

    RE: [CLOSED] [1.0] MVC and Scripts

    Hi,

    Yes, your last sample doesn't work in all browsers.


    1. You have to set false for the WrapByScriptTag property of the PartialExtView instance because you evalute script manually (otherwise js error occurs)
    result.WrapByScriptTag = false;

    2. Use AddTo mode (because you define Panel as container) or use panel's body - containerId: Panel1.body.id (because you use RenderTo mode)


    P.S. May be it is better to wrap eval(script) by try/catch block and show alert if error occur
  6. #6

    RE: [CLOSED] [1.0] MVC and Scripts

    Hello vladimir,

    Sorry my example doesn't show that I've implicitly made the PartialExtResult and PartialExtRenderer automatically set wrapByScriptTag to false and RenderMode to AddTo.

    Still doesn't work in FF3.5.8

    Cheers
  7. #7

    RE: [CLOSED] [1.0] MVC and Scripts

    Hi,

    Can you post partial view loading request's response text from Firebug?
  8. #8

    RE: [CLOSED] [1.0] MVC and Scripts

    <div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; ">Ext.net.append(Ext.getBody(),["<div id=\"idaecbff16299641c79b09345376cdba19_Content\" class=\"x-hidden\">","<script type=\"text/javascript\" language=\"javascript\">","function myExample()","{","alert('Hello World');","};","<\/script>","<div id=\"Example_Container\" style=\"display:inline;\">","
    ","<div id=\"ctl03_idf35883a313db4ef0a3a9bf8baf8ed6c7_Container\" style=\"display:inline;\">","
    
    "].join(''));Ext.net.ResourceMgr.destroyCmp("idaecbff16299641c79b09345376cdba19");new Ext.Panel({id:"idaecbff16299641c79b09345376cdba19",xtype:"panel",border:false,header:false,contentEl:"idaecbff16299641c79b09345376cdba19_Content"});new Ext.form.TextField({id:"Example",renderTo:"Example_Container"});new Ext.Button({renderTo:"ctl03_idf35883a313db4ef0a3a9bf8baf8ed6c7_Container",text:"Test",listeners:{click:{fn:function(el,e){myExample()}}}});Panel1.addAndDoLayout(idaecbff16299641c79b09345376cdba19);

    Thanks again vladimir.


    Cheers,
    Timothy
  9. #9

    RE: [CLOSED] [1.0] MVC and Scripts

    Hi,

    Response is correct. Even if run this code in the FireBug console then textfield and button appear and button's click shows the alert


    Please create separate solution which demonstrates issue. Please do not attach .dll assemblies.


  10. #10

    RE: [CLOSED] [1.0] MVC and Scripts

    vladimir,

    Uploaded.


    Cheers,
    Timothy
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] how to add scripts to a MVC response at runtime
    By RCN in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Feb 24, 2012, 8:44 PM
  2. [CLOSED] Scripts at bottom of page
    By rthiney in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 07, 2011, 7:53 PM
  3. [CLOSED] Latest scripts in SVN?
    By rthiney in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 13, 2011, 7:24 PM
  4. [CLOSED] [1.0] Forcing all ext net scripts to load
    By bsnezw in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 14, 2011, 8:54 PM
  5. [CLOSED] AutoLoad Scripts
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 19, 2009, 11:19 AM

Posting Permissions