I have to integrate a Java applet into a simple asp.net 2.0 control.
This applet is a bought product and cannot be modified. It contains a button designed to be clicked to continue. The button click is linked to a JavaScript function.
So we can see this applet as a black box, eating data and calling a JS function when it’s done.
I have to make a postback when the JS function is called to go to the next page. Easy, I just have to write it. But I would also like to hide the applet, or the div containing it, because the postback trigger some long treatment. The point is that, while waiting, the user can click on the applet button and triggers the postback again.
In my JavaScript called function, I tried many solutions:
- Make 2 postbacks. Of course this doesn’t work, as a postback is a reload of the page
- Hide/show the div or the applet using JavaScript
- Hide/show the div or the applet using jQuery
- Hide/show the div or the applet calling the click event of an invisible button to set Visible = false in the code behind
But it always fails: it seems that the web browser (IE 8.0 or Chrome) waits the end of the postback/JS function to update the page, and don’t bother with some UI update just before.
So here I am:
- I need the postback to go to the next page (I do not control the entire environment where my control is used)
- I have to hide the applet, otherwise the user can re-click on it
- I can’t make a two-step process, like having the JS function hiding the applet and displaying a link to to the next page, involving a new click
My simple control:
<%@ Control Language="C#" AutoEventWireup="false" Codebehind="MyControl.ascx.cs"
Inherits="MyControl" %>
<div id="m_DivPostDisplay" runat="server">
<asp:Label ID="lblState" runat="server" Text="Displaying something like please wait..." />
</div>
<div id="m_DivAppletContainer" runat="server">
<applet name="myApplet" archive="./myJar.jar"
code="Main.class" height="700" width="530" mayscript>
</applet>
</div>
The related javascript (injected when the page load):
<script language='javascript'>
function sendData(data) {
// This is where I try to hide the applet or the div
//.....
// Go to the next page
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(\"nextButtonId\", \"\", true, \"\", \"\", false, true));
}
</script>
Do you have any idea of what could be done to fix my problem?
Thanks 🙂
Finally we asked the applet editor to add a new feature, so we can now disable its buttons when we need.
So when we click on the button, we keep it disabled, launch the postback, and change page when the postback returns.