Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scope changes when passing Function() across iframe

Status
Not open for further replies.

Merkaba

Programmer
Jun 14, 2005
69
US
Hi all,

I am coding a revised version of an application, upgrading it to Ajax following the Model View Controller pattern (MVC Pattern).

A quick break down:

Client UI - Run on IE7 - HTML/Javascript/ExtJs Library/JSON/MS AJAX Extensions

Server - ASP.NET (webforms with no code behind) and a C# Web Service returning JSON

We only use the AJAX Extensions for the JSON Serializer and bits and pieces of its Javascript library, no server-side web controls.

The UI needs to use a DHTML approach to keep objects alive when the page changes, i.e. a navigation header with an imbedded iframe to hold the pages. The navigation holds the Controllers (MVC Pattern) to call the Web Service and the iframe has the calling page holding the View.

For example:
Code:
<html>
<head>
  [b]<script>

    Controller.execute = function(model) {
      [green]// Call js webservice proxy[/green]
      WebService.Execute(model.parameters, callback, error, userContext);

      [green]// WebService C# method signature is:
      // public object Execute(object[] args) { ... }[/green]
    }

  </script>[/b]
</head>
<body>
...

  [red]<iframe>[/red]
   ...
    [b]<script>
      
      View.initialize = function() {
        var model = new Model();
        [green]// Model has an Array() called parameters[/green]
        model.parameters[0] = value;
        window.parent.Controller.execute(model);
      }

      View.initialize();
    </script>[/b]
   ...
  [red]</iframe>[/red]
...
</body>
</html>

When the View.initialize is called (it actually happens when the iframe page is done loading) and it reaches the Controller.execute, the model.parameters is now an Array(), but the value is model.parameters[0] = {0, value} instead of model.parameters[0] = value, failing in the proxy call WebService.Execute.

A Javascript error is alerted by the js proxy generated by the Web Service saying cannot except a parameterless Object[].

Any ideas why the object changes between the iframe and parent? When the Controller is used in the page inside the iframe (no navigation header) it runs fine.

I'd rather stay away from feeding divs HTML fragments with innerHtml instead of using iframes, but this problem is very annoying and there are no clear cut answers to be found. Just hoping someone else saw this before and has either a solution or alternate approach.


Thanks,

-Merk






There will either be World Peace or The World in Pieces. Everything we do plays a part for one of the outcomes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top