Saturday, May 11, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  14] [ 4]  / answers: 1 / hits: 105539  / 15 Years ago, sat, april 25, 2009, 12:00:00

I would like to call a javascript function from an aspx control. For instance, suppose I had:



<html xmlns=http://www.w3.org/1999/xhtml>
<head runat=server>
<title>Untitled Page</title>
<script type=text/javascript>
function test(x, y)
{

}
</script>
</head>
<body>
<form id=form1 runat=server>
<div>
<asp:Button ID=Button1 runat=server Text=Button
onclick=Button1_Click/>
</div>
</form>
</body>
</html>


and in the code behind:



protected void Button1_Click(object sender, EventArgs e)
{
// do stuff (really going to a database to fill x and y)
int[] x = new int[] { 1, 2, 3, 4, 5 };
int[] y = new int[] { 1, 2, 3, 4, 5 };

// call javascript function as test(x,y);
}


Is there a way to do it?


More From » c#

 Answers
105

You can use the Page.ClientScript.RegisterStartupScript method.


[#99651] Monday, April 20, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadyngraysons

Total Points: 455
Total Questions: 109
Total Answers: 98

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
jadyngraysons questions
Thu, Apr 23, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
Tue, Dec 31, 19, 00:00, 4 Years ago
;