May 31, 2016, 11:51 AM
[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:
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>":
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
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.