Wednesday, March 21, 2012

passing a string from the server to client side javascript

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,
LynersPrepare 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" <Lyners@.discussions.microsoft.com> wrote in message
news:DF2717EF-9B7F-4CE7-B78E-973878F7092C@.microsoft.com...
> 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
>
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" <Lyners@.discussions.microsoft.com> wrote in message
news:DF2717EF-9B7F-4CE7-B78E-973878F7092C@.microsoft.com...
> 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
>
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, bu
t
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" <Lyners@.discussions.microsoft.com> wrote in message
> news:DF2717EF-9B7F-4CE7-B78E-973878F7092C@.microsoft.com...
>
>
You are not sending the string to the client.
In your client html
function Page_onLoad() {
var blnVisible = <%= m_strVisible %>;
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 a
n
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 %>;
>
This is normally done with a hidden input control:
<input type=hidden runat=server id=inhMyParameter">
Eliyahu
"Lyners" <Lyners@.discussions.microsoft.com> wrote in message
news:DF2717EF-9B7F-4CE7-B78E-973878F7092C@.microsoft.com...
> 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
>
Incorrect. Perhaps you posted to the wrong question? He was asking how
to pass a string from server to client.
Why do you think is it incorrect?
Eliyahu
"sirfunusa" <sirfunusa@.hotmail.com> wrote in message
news:1144081480.686619.283100@.i39g2000cwa.googlegroups.com...
> Incorrect. Perhaps you posted to the wrong question? He was asking how
> to pass a string from server to client.
>
Not incorrect at all. Use of hidden field is another approach to do the same
thing.
"sirfunusa" <sirfunusa@.hotmail.com> wrote in message
news:1144081480.686619.283100@.i39g2000cwa.googlegroups.com...
> Incorrect. Perhaps you posted to the wrong question? He was asking how
> to pass a string from server to client.
>

0 comments:

Post a Comment