Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I call a javascript function from inside a method?
    text
    copied!<p>I am inside of...</p> <pre><code>public class bgchange : IMapServerDropDownBoxAction { void IServerAction.ServerAction(ToolbarItemInfo info) { Some code... </code></pre> <p>and after "some code" I want to trigger</p> <pre><code>[WebMethod] public static void DoSome() { } </code></pre> <p>Which triggers some javascript. Is this possible?</p> <p>Ok, switch methods here. I was able to call dosome(); which fired but did not trigger the javascript. I have tried to use the registerstartupscript method but don't fully understand how to implement it. Here's what I tried:</p> <pre><code>public class bgchange : IMapServerDropDownBoxAction { void IServerAction.ServerAction(ToolbarItemInfo info) { ...my C# code to perform on dropdown selection... //now I want to trigger some javascript... // Define the name and type of the client scripts on the page. String csname1 = "PopupScript"; Type cstype = this.GetType(); // Get a ClientScriptManager reference from the Page class. ClientScriptManager cs = Page.ClientScript; // Check to see if the startup script is already registered. if (!cs.IsStartupScriptRegistered(cstype, csname1)) { String cstext1 = "alert('Hello World');"; cs.RegisterStartupScript(cstype, csname1, cstext1, true); } } </code></pre> <p>}</p> <p>I got the registerstartupscript code from an msdn example. Clearly I am not implementing it correctly. Currently vs says "An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.ClientScript.get' refering to the piece of code "Page.Clientscript;" Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload