PDA

View Full Version : [CLOSED] Difficulty for IE when PartialView tries to Upload File



cleve
Apr 24, 2013, 11:45 AM
Hi guys,

This problem shows only by IE.

1. This view works fine.



<%@ Control Language="C#" %>
<ext:Window runat="server" ID="win" Layout="FitLayout" CloseAction="Destroy"
Width="300" Height="200" Border="false">
<Items>
<ext:FormPanel runat="server" BodyPadding="20">
<Items>
<ext:FileUploadField runat="server" ID="uField" IDMode="Static" AnchorHorizontal="100%">
<DirectEvents>
<Change Url="/test.aspx/upload" />
</DirectEvents>
</ext:FileUploadField>
</Items>
</ext:FormPanel>
</Items>
<Buttons>
<ext:Button runat="server" Text="Close">
<Listeners>
<Click Handler="#{win}.close();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:Window>




2. This view doesn't work (extra js code block added)




<%@ Control Language="C#" %>
<ext:Window runat="server" ID="win" Layout="FitLayout" CloseAction="Destroy"
Width="300" Height="200" Border="false">
<Items>
<ext:FormPanel runat="server" BodyPadding="20">
<Items>
<ext:FileUploadField runat="server" ID="uField" IDMode="Static" AnchorHorizontal="100%">
<DirectEvents>
<Change Url="/test.aspx/upload" />
</DirectEvents>
</ext:FileUploadField>
</Items>
</ext:FormPanel>
</Items>
<Buttons>
<ext:Button runat="server" Text="Close">
<Listeners>
<Click Handler="#{win}.close();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:Window>
<script type="text/javascript">
Ext.ns("MyNamespace");
</script>



IE prompts an error telling "Access denied" (attached).
Any ideas?

Daniil
Apr 24, 2013, 2:41 PM
Hi @cleve,

Please try to move the script block into the Window's HtmlBin. Does it help?

cleve
Apr 25, 2013, 12:27 AM
Hi @cleve,

Please try to move the script block into the Window's HtmlBin. Does it help?

Sorry, it doesn't work. The following is the complete example. My IE version is 9.0.8112.*.

Controller "Test"



public ActionResult Index()
{
return View(@"~/test/index.aspx");
}

public ActionResult Test(string id)
{
Ext.Net.MVC.PartialViewResult r = this.PartialExtView("~/test/control1.ascx");
r.ContainerId = "c";
r.RenderMode = RenderMode.AddTo;
r.ClearContainer = true;
r.ControlId = "x";
r.IDMode = IDMode.Client;
return r;
}





Index.aspx




<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body id="theBody">
<ext:ResourceManager ID="theManager" runat="server"
ShowWarningOnAjaxFailure="false"
DirectMethodProxy="Ignore"
ScriptMode="Debug">
<Listeners>
</Listeners>
</ext:ResourceManager>
<ext:Viewport runat="server">
<Items>
<ext:Button runat="server" Text="Inject to Upload">
<DirectEvents>
<Click Url="/test.aspx/test" />
</DirectEvents>
</ext:Button>
</Items>
</ext:Viewport>
<ext:Container runat="server" ID="c" />
</body>
</html>



Control1.ascx


<%@ Control Language="C#" %>
<ext:Window runat="server" ID="win" Layout="FitLayout" CloseAction="Destroy"
Width="300" Height="200" Border="false">
<Items>
<ext:FormPanel runat="server" BodyPadding="20">
<Items>
<ext:FileUploadField runat="server" ID="uField" IDMode="Static" AnchorHorizontal="100%">
<DirectEvents>
<Change Url="/test.aspx/upload" />
</DirectEvents>
</ext:FileUploadField>
</Items>
</ext:FormPanel>
</Items>
<Buttons>
<ext:Button runat="server" Text="Close">
<Listeners>
<Click Handler="#{win}.close();" />
</Listeners>
</ext:Button>
</Buttons>
<HtmlBin>
<script type="text/javascript">
Ext.ns("MyNamespace");
</script>
</HtmlBin>
</ext:Window>




I believe it's the problem of IE in a particular version (IE9). Can you guys confirm in your side that problem exists? If it can be reproduced, I'll try something else. Many thanks.

Daniil
Apr 25, 2013, 5:34 AM
I am able to reproduce the problem with this simple example. Can you confirm?

Example

<%@ Page Language="C#" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<ext:ResourceManager runat="server" />

<ext:FormPanel
ID="FormPanel1"
runat="server"
Url="/ASPX/Upload"
Width="300">
<Items>
<ext:FileUploadField runat="server" AnchorHorizontal="100%" />
</Items>
</ext:FormPanel>

<ext:Button runat="server" Text="Submit" Handler="#{FormPanel1}.submit();" />
</body>
</html>


Interesting, but this same page doesn't reproduce the problem with WebForms.

cleve
Apr 25, 2013, 6:31 AM
I am able to reproduce the problem with this simple example. Can you confirm?

Example

<%@ Page Language="C#" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<ext:ResourceManager runat="server" />

<ext:FormPanel
ID="FormPanel1"
runat="server"
Url="/ASPX/Upload"
Width="300">
<Items>
<ext:FileUploadField runat="server" AnchorHorizontal="100%" />
</Items>
</ext:FormPanel>

<ext:Button runat="server" Text="Submit" Handler="#{FormPanel1}.submit();" />
</body>
</html>


Interesting, but this same page doesn't reproduce the problem with WebForms.

Em.. Yea. It show JSON encode error of some kind. But it looks different with the previous of mine. Mine is "Access Denied.".
But when I trace back the source, it focuses the same thing "form.submit()".
When I google search the keyword, It's been generally discussed on iFrame document domain issue. When I further narrow down the problem scope, I come up with some hints not sure if it's helpful.
1. For partial view injection, when "<script type='...." tag is cleared, that is, no JS <script> trunk in partial view control, upload works fine. form.submit won't prompt any error;
2. If JS <script> trunk's added. "Access Denied" error shows. When inspecting the generated code snippet, only several bytes e.g. "<script type='text/javascript'>window.alert('hi');</script>" have been added to the body by Ext.net.append(). Does it mean appending "<script>" breaks the domain consistency?
3. The strangest thing is, when I capture the problematic code snippet and run under "captureRun();", it works fine!




var captureRun = function(){

Ext.ComponentManager.onAvailable("c",function(){Ext.net.append(Ext.getBody(),["<div id=\"x_Content\" class=\"x-hidden\">","<script type=\"text/javascript\">"," // Ext.ns(\"MyNamespace\");","<\/script></div>"].join(''));Ext.net.ResourceMgr.destroyCmp("App.x");Ext.getCmp("c").removeAll();Ext.create("Ext.window.Window",{id:"x_UC_win",border:false,height:200,hidden:false,renderTo:Ext .getBody(),width:300,items:[{xtype:"form",items:[{id:"x_UC_uField",xtype:"filefield",anchor:"100%",directEvents:{change:{fn:function(item,newValue,o ldValue){Ext.net.directRequest({cleanRequest:true, url:"/test.aspx/upload",control:this,action:'Change'});}}}}],bodyPadding:20}],layout:"fit",buttons:[{text:"Close",listeners:{click:{fn:function(item,e){App.x_UC_wi n.close();}}}}],closeAction:"destroy"});Ext.getCmp("c").add({id:"x",border:false,xtype:"container",contentEl:"x_Content"});});

}



Does that mean "window.execScript()" should be checked whether it brings the problem?

Daniil
Apr 25, 2013, 1:00 PM
That example reproduced "Access Denied" error for me.

Ok, here is a simplified example.

View

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Ext.NET Example</title>
</head>
<body>
<ext:ResourceManager runat="server" />

<ext:Button runat="server" Text="Inject to Upload" DirectClickAction="Test" />
</body>
</html>


Partial View

<%@ Control Language="C#" %>

<ext:Window
runat="server"
Width="300"
Height="200"
Layout="FitLayout">
<Items>
<ext:FormPanel runat="server">
<Items>
<ext:FileUploadField runat="server" AnchorHorizontal="100%">
<DirectEvents>
<Change Action="Upload" />
</DirectEvents>
</ext:FileUploadField>
</Items>
</ext:FormPanel>
</Items>
<HtmlBin>
<script type="text/javascript">
Ext.ns("MyNamespace");
</script>
</HtmlBin>
</ext:Window>

Controller Actions

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

public ActionResult Test()
{
return this.PartialExtView("Test");
}

public ActionResult Upload()
{
return new FormPanelResult() { IsUpload = true };
}

It reproduces the "Access denied" error for me regardless there is a <script> in the partial view or not.

Daniil
Apr 25, 2013, 3:31 PM
We think we are facing the same issue as here.
http://stackoverflow.com/questions/1886547/access-is-denied-javascript-error-when-trying-to-access-the-document-object-of
http://stackoverflow.com/questions/12909461/access-denied-on-form-submit

Daniil
Apr 26, 2013, 4:43 AM
I have tried the suggestions from the mentioned links. Unfortunately, nothing seems to be working for me.

I think it is IE9 bug. It appears to be working with IE10.

The best I can suggest to get it working is placing a Window directly on the page.

cleve
Apr 26, 2013, 12:36 PM
I have tried the suggestions from the mentioned links. Unfortunately, nothing seems to be working for me.

I think it is IE9 bug. It appears to be working with IE10.

The best I can suggest to get it working is placing a Window directly on the page.

Can you post some technical details that can fully address this problem?
Limit the scenario to "how to make upload on-the-fly", do you have some suggestions at this moment?

Daniil
Apr 26, 2013, 2:43 PM
Can you post some technical details that can fully address this problem?

Not sure what details you are expecting. Could you clarify? I have no idea why IE denies access on this scenario. IMO, it should not.

The problem seems to be not related to Ext.NET or ExtJS since the same is reproducible without it as it is discussed in the links.


Limit the scenario to "how to make upload on-the-fly", do you have some suggestions at this moment?

Is this not suitable for you?

The best I can suggest to get it working is placing a Window directly on the page.

You could leave it in a user control, but put it on the page at once.

If you are unwilling to put a Window on the page at once, you could try to create it via JavaScript.

cleve
Apr 27, 2013, 12:45 AM
OK. I think I got it. I'll use javascript to include this. Thanks.