English 中文(简体)
Calling Applet function from RegisterStartupScript
原标题:

What I m trying to do is call a Java Applet method immediately after PostBack of an ASP.NET page. In order to accomplish this I m using the ScriptManager.RegisterStartupScript function which I pass a small script block to call a function in the page that then calls the Applet function. It seems multi-step but I get nothing if I just try to call the Applet function from my script block written in the code behind. I ve actually achieved the result I m after but only when I first put a JavaScript alert in the function being called by the code behind script block.

The question is does anyone know how I can get around having to fire an alert prior to the Applet function being called?

Here s some simplified pseudo-code to better describe the scenario.

(.ascx.cs - yes this is in a user control, perhaps that is problematic?)
protected void SetupAppletInput()
{
   string scriptBlock = CreateJavaScriptBlock(dataForApplet);
   ScriptManager.RegisterStartupScript(grvDataSet, grvDataSet.GetType(), "clicky", scriptBlock, true);
}
protected string CreateJavaScriptBlock(String dataForApplet)
{
   StringBuilder sb = new StringBuilder();
   sb.Append("CallAppletFunction(dataForApplet);");
   return sb.ToString();
}

(.ascx)

    function CallAppletFunction(dataForApplet)
    {
        alert("Calling applet function");  // with this line in it works, but is really annoying to have to click the alert off for every PostBack
        document.ReallyCoolApplet.functionToCall(dataForApplet);
    }



Outside of this I believe the only relevant facts to be that the portion of the page being posted back is in an UpdatePanel but the Applet itself is not in an update panel and I believe it isn t getting re-loaded.

Hopefully I explained this adequately. Thanks for any help/thoughts on this!

问题回答

Late but I good way to do this would be to put a call out to javascript from the applet start method.

You should then be able to call the applet properly from there.

Seems a little redundant to do it that way as you can always just have the applet do something right in the start method.

This way you won t have to worry about waiting a set period of time, as soon as the applet loads it will fire the start method.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签