passing a string from the server to client side javascript

Discussion in 'ASP .Net' started by =?Utf-8?B?THluZXJz?=, Mar 31, 2006.

  1. 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
    =?Utf-8?B?THluZXJz?=, Mar 31, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?THluZXJz?=

    Maarten Guest

    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" <> wrote in message
    news:D...
    > 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
    >
    Maarten, Mar 31, 2006
    #2
    1. Advertising

  3. =?Utf-8?B?THluZXJz?=

    Winista Guest

    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" <> wrote in message
    news:D...
    > 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
    >
    Winista, Mar 31, 2006
    #3
  4. 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" <> wrote in message
    > news:D...
    > > 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
    > >

    >
    >
    >
    =?Utf-8?B?THluZXJz?=, Mar 31, 2006
    #4
  5. =?Utf-8?B?THluZXJz?=

    sirfunusa Guest

    You are not sending the string to the client.

    In your client html

    function Page_onLoad() {
    var blnVisible = <%= m_strVisible %>;
    sirfunusa, Mar 31, 2006
    #5
  6. 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 %>;
    >
    >
    =?Utf-8?B?THluZXJz?=, Apr 1, 2006
    #6
  7. This is normally done with a hidden input control:

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

    Eliyahu

    "Lyners" <> wrote in message
    news:D...
    > 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
    >
    Eliyahu Goldin, Apr 2, 2006
    #7
  8. =?Utf-8?B?THluZXJz?=

    sirfunusa Guest

    Incorrect. Perhaps you posted to the wrong question? He was asking how
    to pass a string from server to client.
    sirfunusa, Apr 3, 2006
    #8
  9. =?Utf-8?B?THluZXJz?=

    Winista Guest

    Not incorrect at all. Use of hidden field is another approach to do the same
    thing.

    "sirfunusa" <> wrote in message
    news:...
    > Incorrect. Perhaps you posted to the wrong question? He was asking how
    > to pass a string from server to client.
    >
    Winista, Apr 3, 2006
    #9
  10. Why do you think is it incorrect?

    Eliyahu

    "sirfunusa" <> wrote in message
    news:...
    > Incorrect. Perhaps you posted to the wrong question? He was asking how
    > to pass a string from server to client.
    >
    Eliyahu Goldin, Apr 3, 2006
    #10
  11. =?Utf-8?B?THluZXJz?=

    sirfunusa Guest

    You never set the value.
    sirfunusa, Apr 3, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ken busse
    Replies:
    2
    Views:
    444
  2. =?Utf-8?B?Qw==?=
    Replies:
    1
    Views:
    3,214
    Hermit Dave
    Jan 16, 2004
  3. Shaul Feldman
    Replies:
    0
    Views:
    830
    Shaul Feldman
    Apr 16, 2004
  4. Mike Fellows
    Replies:
    8
    Views:
    421
    Eliyahu Goldin
    Jun 29, 2004
  5. Replies:
    4
    Views:
    7,282
    Eliyahu Goldin
    Jul 13, 2006
Loading...

Share This Page