Connecting Tech Pros Worldwide Forums | Help | Site Map

Accessing Server side Array Variable From Client Side

Newbie
 
Join Date: Aug 2006
Posts: 1
#1: Aug 7 '06
Hi

I'm Satish Kumar, new member of a group.

Is it possible to access a server side(VB.NET) array variable from Client Side(Javascript)

My VB Page Code:

Public x() As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim p As Integer
For p = 0 To 2
x(p) = p
Next
End Sub

My Aspx Page Code:
<script>
for(var j=0;j<3;j++)
{
alert(<%= x[p] %>);
}
</script>

Newbie
 
Join Date: May 2007
Posts: 1
#2: May 8 '07

re: Accessing Server side Array Variable From Client Side


Yes it is possible

For e.g SomeArrayTypes is a variable at server side which you want to access client side

you can use

var types = [<%=SomeArrayTypes %>];
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,719
#3: May 9 '07

re: Accessing Server side Array Variable From Client Side


You could store the array into a hidden field.
You can do this through using ClientScript.RegisterHiddenField(...).
This will write the array into a hidden field which you can then access using your JavaScript code.

For an example on how to do this check out this article provided by MSDN on ClientScript.RegisterHiddenField.

Cheers!

-Frinny
Reply