Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > passing a string from the server to client side javascript

Reply
Thread Tools

passing a string from the server to client side javascript

 
 
=?Utf-8?B?THluZXJz?=
Guest
Posts: n/a
 
      03-31-2006
Hello all,
I have an ASP.NET website where one of my pages contain javascript that is a
check to see if anydata within a datagrid has changed. My problem is that it
takes a considerable amount of time to populate the array in the javascript
after the datagrid is populated.

What I am thinking of doing is creating a comma delimited string on the
server side (.vb) and then have the javascript pick it up through array()....

My problem that I am trying to figure out is how do I pass a string that is
created in a server side function back to the client so that a javascript
function could read it and populate an array.

Does anybody have any pointers how to do this?

Thank you,
Lyners

 
Reply With Quote
 
 
 
 
Maarten
Guest
Posts: n/a
 
      03-31-2006
In your aspx file:

<%# MyString%>

In your VB-file:
Protected MyString as string = "m,y,s,t,r,i,n,g"

Hope this helps you

"Lyners" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Hello all,
> I have an ASP.NET website where one of my pages contain javascript that is
> a
> check to see if anydata within a datagrid has changed. My problem is that
> it
> takes a considerable amount of time to populate the array in the
> javascript
> after the datagrid is populated.
>
> What I am thinking of doing is creating a comma delimited string on the
> server side (.vb) and then have the javascript pick it up through
> array()....
>
> My problem that I am trying to figure out is how do I pass a string that
> is
> created in a server side function back to the client so that a javascript
> function could read it and populate an array.
>
> Does anybody have any pointers how to do this?
>
> Thank you,
> Lyners
>



 
Reply With Quote
 
 
 
 
Winista
Guest
Posts: n/a
 
      03-31-2006
Prepare the commans separated string and then write it in JS block using
RegisterclientScriptBlock kind of methods. And then have another JS function
implementted that picks up this string and populate what ever you are
populating.

"Lyners" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Hello all,
> I have an ASP.NET website where one of my pages contain javascript that is
> a
> check to see if anydata within a datagrid has changed. My problem is that
> it
> takes a considerable amount of time to populate the array in the
> javascript
> after the datagrid is populated.
>
> What I am thinking of doing is creating a comma delimited string on the
> server side (.vb) and then have the javascript pick it up through
> array()....
>
> My problem that I am trying to figure out is how do I pass a string that
> is
> created in a server side function back to the client so that a javascript
> function could read it and populate an array.
>
> Does anybody have any pointers how to do this?
>
> Thank you,
> Lyners
>



 
Reply With Quote
 
=?Utf-8?B?THluZXJz?=
Guest
Posts: n/a
 
      03-31-2006
Thanks Maarten, but my string keeps coming back empty. I had a simular setup
prior to your comment, I changed the Public string to a protected string, but
still no dice.

Here is my declaration and my statement that is creating the string:

Protected strIds As String = "Start"

In my loop I do the following;

dblRecordCounter = dblRecordCounter + 1
strIds = strIds & "," & "MyDataGrid__ctl" + Str(dblRecordCounter
+ 2) + "_txtField"

In the aspx file I have this;
ServerString = new String('<%# strIds%>');
var ids = ServerString.split(',');

but ids[0] or 1,2,3,4,5.... is blank

I know I am missing something simple. Can you see it?

Thank you,
Lyner
"Maarten" wrote:

> In your aspx file:
>
> <%# MyString%>
>
> In your VB-file:
> Protected MyString as string = "m,y,s,t,r,i,n,g"
>
> Hope this helps you
>
> "Lyners" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
> > Hello all,
> > I have an ASP.NET website where one of my pages contain javascript that is
> > a
> > check to see if anydata within a datagrid has changed. My problem is that
> > it
> > takes a considerable amount of time to populate the array in the
> > javascript
> > after the datagrid is populated.
> >
> > What I am thinking of doing is creating a comma delimited string on the
> > server side (.vb) and then have the javascript pick it up through
> > array()....
> >
> > My problem that I am trying to figure out is how do I pass a string that
> > is
> > created in a server side function back to the client so that a javascript
> > function could read it and populate an array.
> >
> > Does anybody have any pointers how to do this?
> >
> > Thank you,
> > Lyners
> >

>
>
>

 
Reply With Quote
 
sirfunusa
Guest
Posts: n/a
 
      03-31-2006
You are not sending the string to the client.

In your client html

function Page_onLoad() {
var blnVisible = <%= m_strVisible %>;

 
Reply With Quote
 
=?Utf-8?B?THluZXJz?=
Guest
Posts: n/a
 
      04-01-2006
I knew it was something like this, but another question, because I still
don't have it working. Does the javascript fire off the Page_onLoad()
everytime the page is loaded? Because I put an alert in the onLoad part and
it never fired, which leads me to think that in the body tag I need to put an
onLoad event to pick up the string.

Correct or not?

Thans alot!

"sirfunusa" wrote:

> You are not sending the string to the client.
>
> In your client html
>
> function Page_onLoad() {
> var blnVisible = <%= m_strVisible %>;
>
>

 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      04-02-2006
This is normally done with a hidden input control:

<input type=hidden runat=server id=inhMyParameter">

Eliyahu

"Lyners" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Hello all,
> I have an ASP.NET website where one of my pages contain javascript that is
> a
> check to see if anydata within a datagrid has changed. My problem is that
> it
> takes a considerable amount of time to populate the array in the
> javascript
> after the datagrid is populated.
>
> What I am thinking of doing is creating a comma delimited string on the
> server side (.vb) and then have the javascript pick it up through
> array()....
>
> My problem that I am trying to figure out is how do I pass a string that
> is
> created in a server side function back to the client so that a javascript
> function could read it and populate an array.
>
> Does anybody have any pointers how to do this?
>
> Thank you,
> Lyners
>



 
Reply With Quote
 
sirfunusa
Guest
Posts: n/a
 
      04-03-2006
Incorrect. Perhaps you posted to the wrong question? He was asking how
to pass a string from server to client.

 
Reply With Quote
 
Winista
Guest
Posts: n/a
 
      04-03-2006
Not incorrect at all. Use of hidden field is another approach to do the same
thing.

"sirfunusa" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Incorrect. Perhaps you posted to the wrong question? He was asking how
> to pass a string from server to client.
>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      04-03-2006
Why do you think is it incorrect?

Eliyahu

"sirfunusa" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Incorrect. Perhaps you posted to the wrong question? He was asking how
> to pass a string from server to client.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a value from server side to client side kimberly.walker@consultant.com ASP .Net 4 07-13-2006 09:07 AM
Passing data from server side to client side? Mike Fellows ASP .Net 8 06-29-2004 03:28 PM
suggestions on: Create/delete/modify element(s) for server side from Javascript/client-side? Shaul Feldman ASP .Net 0 04-16-2004 09:55 PM
Calling client side Javascript from a server side button =?Utf-8?B?Qw==?= ASP .Net 1 01-16-2004 05:56 PM
Passing a text string from the server side to a client side function ken busse ASP .Net 2 11-24-2003 08:18 AM



Advertisments