When the user clicks the button, I want to test the C# code side. The method in the C# function should call a JavaScript function to display an alert with the results of a C# public variable. However, it seems that nothing is being called at all. At the bottom of the ButtonRequest_Click
function, I included
Page.ClientScript.RegisterStartupScript(this.GetType(), "CreateIsm();", "CreateIsm();", true);
to invoke the CreateIsm();
function in JavaScript. Could this be why it's not working?
Here is the C# code snippet:
public Collection<PSObject> output = new Collection<PSObject>();
public string deviceName = "";
public string ipAddresses = "";
public string YourScript = "";
protected void ButtonRequest_Click(object sender, EventArgs e)
{
//Code for ButtonRequest_Click function...
}
Javascript on aspx side in html:
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" CodeBehind="~/Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js" type="text/javascript"></script>
<script>
CreateIsm = function (funct) {
alert('<%=ipAddresses%>');
alert('<%=deviceName%>');
};
</script>
</head>
<body>
<form id="form1" runat="server">
//the are html codes here but I cut it off except ButtonRequest
<asp:Button ID="ButtonRequest" runat="server" Text="Request" Visible="False"
onclick="ButtonRequest_Click" />
</form>
</body>
</html>