passing a string from the server to client side javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lyners

    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,
    Lyners

  • Winista

    #2
    Re: passing a string from the server to client side javascript

    Prepare the commans separated string and then write it in JS block using
    RegisterclientS criptBlock kind of methods. And then have another JS function
    implementted that picks up this string and populate what ever you are
    populating.

    "Lyners" <Lyners@discuss ions.microsoft. com> wrote in message
    news:DF2717EF-9B7F-4CE7-B78E-973878F7092C@mi crosoft.com...[color=blue]
    > 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
    >[/color]


    Comment

    • Maarten

      #3
      Re: passing a string from the server to client side javascript

      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@discuss ions.microsoft. com> wrote in message
      news:DF2717EF-9B7F-4CE7-B78E-973878F7092C@mi crosoft.com...[color=blue]
      > 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
      >[/color]


      Comment

      • Lyners

        #4
        Re: passing a string from the server to client side javascript

        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;

        dblRecordCounte r = dblRecordCounte r + 1
        strIds = strIds & "," & "MyDataGrid__ct l" + Str(dblRecordCo unter
        + 2) + "_txtField"

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

        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:
        [color=blue]
        > 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@discuss ions.microsoft. com> wrote in message
        > news:DF2717EF-9B7F-4CE7-B78E-973878F7092C@mi crosoft.com...[color=green]
        > > 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
        > >[/color]
        >
        >
        >[/color]

        Comment

        • sirfunusa

          #5
          Re: passing a string from the server to client side javascript

          You are not sending the string to the client.

          In your client html

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

          Comment

          • Lyners

            #6
            Re: passing a string from the server to client side javascript

            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:
            [color=blue]
            > You are not sending the string to the client.
            >
            > In your client html
            >
            > function Page_onLoad() {
            > var blnVisible = <%= m_strVisible %>;
            >
            >[/color]

            Comment

            • Eliyahu Goldin

              #7
              Re: passing a string from the server to client side javascript

              This is normally done with a hidden input control:

              <input type=hidden runat=server id=inhMyParamet er">

              Eliyahu

              "Lyners" <Lyners@discuss ions.microsoft. com> wrote in message
              news:DF2717EF-9B7F-4CE7-B78E-973878F7092C@mi crosoft.com...[color=blue]
              > 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
              >[/color]


              Comment

              • sirfunusa

                #8
                Re: passing a string from the server to client side javascript

                Incorrect. Perhaps you posted to the wrong question? He was asking how
                to pass a string from server to client.

                Comment

                • Eliyahu Goldin

                  #9
                  Re: passing a string from the server to client side javascript

                  Why do you think is it incorrect?

                  Eliyahu

                  "sirfunusa" <sirfunusa@hotm ail.com> wrote in message
                  news:1144081480 .686619.283100@ i39g2000cwa.goo glegroups.com.. .[color=blue]
                  > Incorrect. Perhaps you posted to the wrong question? He was asking how
                  > to pass a string from server to client.
                  >[/color]


                  Comment

                  • Winista

                    #10
                    Re: passing a string from the server to client side javascript

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

                    "sirfunusa" <sirfunusa@hotm ail.com> wrote in message
                    news:1144081480 .686619.283100@ i39g2000cwa.goo glegroups.com.. .[color=blue]
                    > Incorrect. Perhaps you posted to the wrong question? He was asking how
                    > to pass a string from server to client.
                    >[/color]


                    Comment

                    • sirfunusa

                      #11
                      Re: passing a string from the server to client side javascript

                      You never set the value.

                      Comment

                      Working...