Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: can u set client script variables from code behind file?


Message #1 by "dmitri kalmar" <dmitrikal@y...> on Thu, 3 Jan 2002 17:21:44
i want to programmatically (from code behind file) set the value of a 

Javascript variable (to be run at client) 



is there such a thing as a JScript control? just like an HTMLControl or 

ASP WebControl. 



lets say the <script> resides in MyPage.aspx and the code behind file is 

MyPage.cs...



MyPage.aspx:

<script language=javascript id=MyScript>

  var productID = "";

  alert("productID = " + productID);

</script>



within MyPage.cs, surely you can do something vaguely resembling this:

  MyScript.productID = "1"; 



i need to set the value of productID from within the .cs file. the the 

only way i see to do it is to use a Label or Div in the aspx page, and 

then set the text of that to be the entire javascript, from <script> to 

</script>. this seems klugey, given the new .Net server control approach. 



TIA!



-d

Message #2 by Todd Carrico <ToddC@m...> on Thu, 3 Jan 2002 11:28:57 -0600
I have used hidden HTML input fields, and set their value at runtime.



Classic ASP:

<Input Type="hidden" Value="<%= SomeVariable %>">



Then just reference the field from JavaScript.



Don't see why it wouldn't work in ASP.NET ;)



tc





-----Original Message-----

From: dmitri kalmar [mailto:dmitrikal@y...] 

Sent: Thursday, January 03, 2002 11:22 AM

To: ASP+

Subject: [aspx] can u set client script variables from code behind file?



i want to programmatically (from code behind file) set the value of a 

Javascript variable (to be run at client) 



is there such a thing as a JScript control? just like an HTMLControl or 

ASP WebControl. 



lets say the <script> resides in MyPage.aspx and the code behind file is 

MyPage.cs...



MyPage.aspx:

<script language=javascript id=MyScript>

  var productID = "";

  alert("productID = " + productID);

</script>



within MyPage.cs, surely you can do something vaguely resembling this:

  MyScript.productID = "1"; 



i need to set the value of productID from within the .cs file. the the 

only way i see to do it is to use a Label or Div in the aspx page, and 

then set the text of that to be the entire javascript, from <script> to 

</script>. this seems klugey, given the new .Net server control approach. 



TIA!



-d







  Return to Index