HighTechTalks DotNet Forums  

Server-Side Client-Side Array

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss Server-Side Client-Side Array in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Morphious
 
Posts: n/a

Default Server-Side Client-Side Array - 03-29-2005 , 03:35 PM






I created a server-side array and now I need to populate it to a client-side
array - how would I do this?

Reply With Quote
  #2  
Old   
monae
 
Posts: n/a

Default RE: Server-Side Client-Side Array - 04-06-2005 , 02:41 AM






You can literally write it in or you can use ASP.NET's
RegisterClientSideScript(..). I consider the latter useless. It really does
not save you anything and is cryptic to boot.

public class WebForm1 : System.Web.UI.Page
{
string crlf = Environment.NewLine;
private void Page_Load(object sender, System.EventArgs e)
{
String[]testarray = {"red","blue","green"};
MakeClientSideArray(testarray);
MSExample();
}
// Writing it in...
// If you have a big array, use a StringBuilder object instead of string
// concatenation to build up your string.
private void MakeClientSideArray(String[] csarray)
{
string astr = "";
// Use just the following line for testing before you go on.
//astr += "document.write('Script is OK')" + crlf;
Response.Write("<script language='Javascript'>" + crlf);
astr += "var colors = new Array(1)" + crlf;
for ( int ii = 0 ; ii < csarray.GetLength(0) ; ii++)
{
astr += "colors[" + ii.ToString() + "] = '" + csarray[ii] + "'" + crlf;
}
Response.Write(astr);
//If you have a problem with the following line, separate out the forward
slash
// into a separate string. The MSExample does this.
// I think the problem went away in 1.1 because this works ok for me now
// but used to be a problem in the 1.0 version.
Response.Write("</script>");
}

// The RegisterClientSideScript example as written by Microsoft
// It could not possibly work so I modified it liberally.
// It doesn't have anything to do with arrays, but you could appropriately
modify it.
// To actually call this, you will need to put a button on the form and
// call it in the button's onclick event, which you will have to insert by
hand.
public void MSExample()
{
String scriptString = "<script language=JavaScript> function DoClick() {";
scriptString += "alert('Welcome to Microsoft .NET'); }<";
scriptString += "/";
scriptString += "script>";

if(!this.IsClientScriptBlockRegistered("clientScri pt"))
this.RegisterClientScriptBlock("clientScript", scriptString);
}
}

"Morphious" wrote:

Quote:
I created a server-side array and now I need to populate it to a client-side
array - how would I do this?

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.