[CLOSED] ASP.Net WebForms Callback not processed since Upgrade from 1.7 when DisableViewState="true"

  1. #1

    [CLOSED] ASP.Net WebForms Callback not processed since Upgrade from 1.7 when DisableViewState="true"

    Ext.Net version: 3.3.0
    ASP.Net version: 4.0.30319

    Hello,

    We are currently upgrading Ext.Net from 1.7 to 3.3. On one page we are mixing Ext.Net with another 3rd party component which is a plain WebControl (non-Ext). It uses the WebForms "Callback" mechanism (the WebControl implements the ICallbackEventHandler interface) to communicate with our application code.

    This worked perfectly in 1.7, but since the upgrade the callback is not executed anymore (verified by setting a break point with the debugger), and instead of the callback result the HTML page is returned to the browser (verified with the network tab in Chrome's dev tools).

    Here's an .aspx and a representative WebControl to reproduce the issue:
    TestPage.aspx:
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Register Assembly="ASSEMBLY NAME GOES HERE" Namespace="Test" TagPrefix="test" %>
    
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server" DisableViewState="true"/>
            <ext:Container runat="server">
                <Content>
                    <test:TestCallbackControl runat="server" ID="Test"/>
                </Content>
            </ext:Container>
        </form>
    </body>
    </html>
    TestCallbackControl.cs:
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Test {
        public class TestCallbackControl : WebControl, ICallbackEventHandler {
            protected override void Render(HtmlTextWriter tw) {
                tw.WriteLine(@"<a href='#' onclick='TestCallbackStart(); return false;'>Test the Callback</a>");
    
                var callbackRef = Page.ClientScript.GetCallbackEventReference(this, "null", "TestCallbackDone", "null");
                tw.WriteLine(@"<script type='text/javascript'>");
                tw.WriteLine(@"function TestCallbackStart() { " + callbackRef + "; }");
                tw.WriteLine(@"function TestCallbackDone(result) { alert(result); }");
                tw.WriteLine(@"</script>");
            }
    
            public void RaiseCallbackEvent(string eventArgument) {
            }
    
            public string GetCallbackResult() {
                return "Callback returned";
            }
        }
    }
    The control will render a link, which when clicked performs the callback and alerts the result. The expected behavior is that the message "Callback returned" is alerted in the Browser. This is what happens when the sample is run under Ext.Net 1.7 or when the ext:ResourceManager (and the ext:Container) is removed from the page.

    The first error that happens is that the WebForms javascript code cannot resolve the variable "theForm". This can be fixed by including the following script tag before the "</form>":
    window.theForm = document.forms['form1'];
    if (!theForm) {
        window.theForm = document.form1;
    }
    
    window.__doPostBack = function (eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    This is ugly but I could live with that.

    Then the callback is successfully sent to the server, but the callback is not executed and the HTML is returned again instead. I don't know why that is.

    Since this is a 3rd party component we cannot modify it, and we also cannot wrap it in an non-Ext.net IFrame because the component needs to interact with the rest of the page. We don't want to set DisableViewState="false" because the ViewState is quite large on our pages and we don't want to send it around all the time. Also re-enabling view state causes the error "An error has occurred because a control with id [...] could not be located or a different control is assigned to the same ID after postback" to occur on every DirectMethod call (probably because our pages are not written with ViewState in mind). Some help on getting the callbacks to work again would be much appreciated.

    Best regards,
    Raphael Robatsch
    Last edited by fabricio.murta; Jun 02, 2016 at 3:47 PM.
  2. #2
    Hello Raphael!

    Sorry to hear you are having issues porting some code from 1.x to 3.x series. That happens as the technology step is considerable between the two versions.

    Before we dive in the example you provided, you stated that you couldn't leave the 3rd-party control in an iframe because it needs to interacts with the rest of the page.

    If that's the only reason you don't want it on an IFrame, you may possibly reconsider it if you implement two-way iframe communication in a similar way our example here illustrates: Panel > Basic > IFrame Communication.

    Would that be an acceptable solution for you?
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello,

    I've been thinking about this possibility too, but unfortunately one of the interactions the component does is drag and drop. To be specific it allows DOM elements from the page to be dragged into the component. The component also renders context menus and tool tips which would be cut off by the iframe if it is opened near the frame border.

    I am hoping to avoid having to re-implement those features so they work cross-frame, but if WebForms callbacks are not supported anymore in Ext.Net 3 I see no other choice.

    Best regards,
    Raphael Robatsch
  4. #4
    Hello Raphael!

    Sorry but I believe the combination you are trying to use is supposed not to work and became the default since Ext.NET v2.

    For some reason I couldn't find this forum thread yesterday although I searched for the same keywords I did now and found it, but now that it has been found, please consider it: Error: 'theForm' is undefined.

    This is like, disabling ViewState pretty much disables the functionality of postback handling implemented by ICallbackEventHandler.
    Fabrício Murta
    Developer & Support Expert
  5. #5
    I feared that this was the case, we will work around this issue. Thanks for the confirmation.

    Best regards,
    Raphael Robatsch

Similar Threads

  1. Replies: 8
    Last Post: Aug 11, 2015, 1:52 PM
  2. Replies: 1
    Last Post: Apr 23, 2014, 2:54 AM
  3. Replies: 5
    Last Post: Mar 28, 2014, 1:11 AM
  4. [CLOSED] Using DirectMethod inside a ListView with disableViewState="true"
    By SouthDeveloper in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Oct 06, 2012, 7:29 PM
  5. Replies: 5
    Last Post: May 02, 2012, 5:37 PM

Posting Permissions