Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy code behind C# button_clicked function doesn't call Javascript function?
    primarykey
    data
    text
    <p>I want to test the C# code side when user click the button, the method in C# function should be able to call the JavaScript function to show alert C# public variable results. Somehow it doesn't call anything at all. At the bottom of <code>ButtonRequest_Click</code> function, I wrote <code>Page.ClientScript.RegisterStartupScript(this.GetType(), "CreateIsm();", "CreateIsm();", true);</code> to call <code>CreateIsm();</code> function in JavaScript. Maybe this doesn't work?</p> <p>Here is C# codes,</p> <pre><code>public Collection&lt;PSObject&gt; output = new Collection&lt;PSObject&gt;(); public string deviceName = ""; public string ipAddresses = ""; public string YourScript = ""; protected void ButtonRequest_Click(object sender, EventArgs e) { deviceName = string.Empty; ipAddresses = string.Empty; HiddenName.Visible = false; string str = ""; string ipAddress = ""; string name = ""; var tbids = (List&lt;string&gt;)Session["tbids"]; //create a powershell Runspace runSpace = RunspaceFactory.CreateRunspace(); runSpace.Open(); RunspaceInvoke invoke = new RunspaceInvoke(); Pipeline pipeline = runSpace.CreatePipeline(); Command invokeScript = new Command("Invoke-Command"); //Add powershell script file and arguments into scriptblock ScriptBlock sb = invoke.Invoke(@"{D:\Scripts\Get-FreeAddress.ps1 '" + DropDownListContainer.SelectedValue + "' " + DropDownListIP.SelectedValue + "}")[0].BaseObject as ScriptBlock; invokeScript.Parameters.Add("scriptBlock", sb); invokeScript.Parameters.Add("computername", TextBoxServer.Text); pipeline.Commands.Add(invokeScript); Collection&lt;PSObject&gt; output = pipeline.Invoke(); runSpace.Close(); Runspace runSpace2 = RunspaceFactory.CreateRunspace(); runSpace2.Open(); foreach(PSObject psObject in output) { ipAddress = "" + psObject; ipAddresses += "" + psObject; foreach(var id in tbids) try { name = Request[id]; deviceName += Request[id] + "\r\n"; Pipeline pipeline2 = runSpace2.CreatePipeline(); Command invokeScript2 = new Command("Invoke-Command"); //Add powershell script file and arguments into scriptblock ScriptBlock sb2 = invoke.Invoke(@"{D:\Scripts\Set-IPAddress.ps1 " + ipAddress + " " + name + "}")[0].BaseObject as ScriptBlock; invokeScript2.Parameters.Add("scriptBlock", sb2); invokeScript2.Parameters.Add("computername", TextBoxServer.Text); pipeline2.Commands.Add(invokeScript2); tbids.RemoveAt(0); Collection&lt;PSObject&gt; output2 = pipeline2.Invoke(); foreach(PSObject psObject2 in output2) { str = str + psObject2; } break; } catch { } } Page.ClientScript.RegisterStartupScript(this.GetType(), "CreateIsm();", "CreateIsm();", true); } </code></pre> <p>Javascript on aspx side in html,</p> <pre><code>&lt;%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" CodeBehind="~/Default.aspx.cs" Inherits="_Default" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head id="Head1" runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script&gt; CreateIsm = function (funct) { alert('&lt;%=ipAddresses%&gt;'); alert('&lt;%=deviceName%&gt;'); }; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; //the are html codes here but I cut it off except ButtonRequest &lt;asp:Button ID="ButtonRequest" runat="server" Text="Request" Visible="False" onclick="ButtonRequest_Click" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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