473,408 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Populating Javascript array from vb.net

MW
How can I poplute a javascript array from vb.net? I would prefer to do this
from codebehind.

Michael
Nov 18 '05 #1
4 5185
Hi,

You an use Page.RegisterArrayDeclaration method for that.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"MW" <Pl****@NoSpam.com> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl...
How can I poplute a javascript array from vb.net? I would prefer to do this from codebehind.

Michael

Nov 18 '05 #2
Create a String that represents the code and register it as a client script

dim str as String = "<script>var i=new
Array();i[0]=234;i[1]=543;i[2]=598;</script>"
page.RegisterClientScriptBlock(""myScript",str)

(this method does not show up in intellisense, but you can see it if you
look at the page class through the object browser)

"MW" <Pl****@NoSpam.com> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl...
How can I poplute a javascript array from vb.net? I would prefer to do this from codebehind.

Michael

Nov 18 '05 #3
Hi,
you can add the following code in your page to create an array also
you can edit this code to add your on logic for assigning the values in to
the array.

Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
' Put user code to initialize the page here
Me.RegisterStartupScript("SetFocusScript",
PopulateJavaScriptArray())
End Sub
Private Function PopulateJavaScriptArray() As String
' Declaring the Number of Items in the Array
Dim noOfItems As Integer = 10
Dim myJavaScript As StringBuilder = New StringBuilder()
myJavaScript.Append("<script language='Javascript'>")
myJavaScript.Append(" var myArrayInJavaScript = new Array("+
noOfItems +");")
myJavaScript.Append(" myArrayInJavaScript[5] ='Hello
There...!!';")
myJavaScript.Append(" alert(myArrayInJavaScript[5]);")
myJavaScript.Append("</script>")
Return myJavaScript.ToString()
End Function

HTH
Regards
Ashish M Bhonkiya
"MW" <Pl****@NoSpam.com> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl...
How can I poplute a javascript array from vb.net? I would prefer to do this from codebehind.

Michael

Nov 18 '05 #4
check this code

String scriptString = "<script language=JavaScript> function doClick() {";
scriptString += "for(var index=0;index < myArray.length;index++)";
scriptString += " myArray[index].show(); } <";
scriptString += "/" + "script>";

RegisterStartupScript("arrayScript", scriptString);
RegisterArrayDeclaration("myArray", "new obj('x'),new obj('y'),new
obj('z')");

you can declare your array using your values.

Av.

"MW" <Pl****@NoSpam.com> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl...
How can I poplute a javascript array from vb.net? I would prefer to do
this
from codebehind.

Michael

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: | last post by:
Trying to learn about manipulating collections of objects, and populating these objects dynamically from datasources. Could someone post a code sample that shows the following: Instantiating a...
8
by: jack-b | last post by:
Hi, I have a list box which displays countries names and a second listbox which displays their cites (based on the selection made in ListBox 1) If the user selects USA i want to display cities...
1
by: Archuaakash23 | last post by:
I have a form with a list of checkboxes. The form is created dynamically from a database and the checkboxes are assigned to each item that is returned in the database (each item has a unique ID). I...
7
by: sosamv | last post by:
Hi all!, I'm creating a app with PHP and MySQL, the system administrator is capable of creating profiles, on each profile we create, we add a custom access menu (a javascript tree view menu), theres...
6
omerbutt
by: omerbutt | last post by:
hi there i am making a scrapbook application i which i have some emoticons also i had to make a preview section for writing a scrap in which i have to show the emoticons also that are written in...
4
by: Peter Duniho | last post by:
On Thu, 14 Aug 2008 18:56:00 -0700, Phill <Phill@discussions.microsoft.comwrote: For future reference, if you are asking for help with an error (compile or execution), you really should post...
6
by: cathyisfrustrated | last post by:
Hey, I've been trying to learn javascript for a few days. I'm a bit stuck! I'd appreciate any links to get me going in the right direction or any advice I can get. I've written a...
0
by: jac130 | last post by:
i need to populate an array with grades. there is an 'add students & grades' button. user is prompted by input box to enter a students name, then another input box to enter their grade. the student's...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.