register dynamic javacript with RegisterStartupScript

Discussion in 'ASP .Net' started by Jason Chan, Nov 19, 2005.

  1. Jason Chan

    Jason Chan Guest

    I have a paging datalist which show a list of thumbnail.

    Above the datalist there is a dropdown to jump to different paging.
    On Page_load, I bind the datalist according to the current page.
    On the same time, I have to generate a dynamic javascript to load the image
    in the datalist to an javascript array

    So I use Page.RegisterStartupScript to insert the script just before the
    closing form tag.

    The code works fine for the first page, however when I jump to another page,
    from the source code, I found that the JavaScript keep showing the script of
    the first page. This make my page doesn't work properly

    That is, for example.

    page 1 of datalist load 5 images (1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg)
    the javascript of the page 1 is dynamic generated and registered
    img[0] = "1.jpg";img[1] = "2.jpg";img[2] = "3.jpg";img[3] = "4.jpg";img[4] =
    "5.jpg";

    when I jump to page 2, it load another 5 images (6.jpg, 7.jpg, 8.jpg, 9.jpg,
    10.jpg)
    the javascript should look like
    img[0] = "6.jpg";img[1] = "7.jpg";img[2] = "8.jpg";img[3] = "9.jpg";img[4] =
    "10.jpg";

    However, it just keep showing the first script, any idea?
    P.S using ASP.NET 2.0
     
    Jason Chan, Nov 19, 2005
    #1
    1. Advertising

  2. Without seeing any code, it is not possible to determine the exact cause,
    but this is my theory:

    In your page_load you have something similar to:

    If not ispostback then
    GetPage(1)
    DoDataBinding()
    end if

    GenerateJavascript()

    And you have in a paging handler:
    GetPage(e.NewPageIndex)
    DoDataBinding()

    On first load of the page, the page load will load the first page of data
    and bind the data, then will create the javascript for your page.

    On subsequent postbacks, the page load will run first, creating the
    javascript for the first page, then the event handler will fire, which
    loads the next page and binds it to the datalist.

    If this is the correct scenario, you will need to call the method that
    creates the javascript in your event handler so it is current with the
    data that has been loaded. The base problem I suspect is that you have
    your javascript generate call in the page load which is fired before the
    new page data is loaded.

    Hope this helps.

    ----
    700cb Development, Inc.
    http://www.700cb.net
    ..NET utilities, developer tools,
    and enterprise solutions

    "Jason Chan" <> wrote in
    news::

    > I have a paging datalist which show a list of thumbnail.
    >
    > Above the datalist there is a dropdown to jump to different paging.
    > On Page_load, I bind the datalist according to the current page.
    > On the same time, I have to generate a dynamic javascript to load the
    > image in the datalist to an javascript array
    >
    > So I use Page.RegisterStartupScript to insert the script just before
    > the closing form tag.
    >
    > The code works fine for the first page, however when I jump to another
    > page, from the source code, I found that the JavaScript keep showing
    > the script of the first page. This make my page doesn't work properly
    >
    > That is, for example.
    >
    > page 1 of datalist load 5 images (1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg)
    > the javascript of the page 1 is dynamic generated and registered
    > img[0] = "1.jpg";img[1] = "2.jpg";img[2] = "3.jpg";img[3] =
    > "4.jpg";img[4] = "5.jpg";
    >
    > when I jump to page 2, it load another 5 images (6.jpg, 7.jpg, 8.jpg,
    > 9.jpg, 10.jpg)
    > the javascript should look like
    > img[0] = "6.jpg";img[1] = "7.jpg";img[2] = "8.jpg";img[3] =
    > "9.jpg";img[4] = "10.jpg";
    >
    > However, it just keep showing the first script, any idea?
    > P.S using ASP.NET 2.0
    >
    >
    >




    --
     
    cbDevelopment, Dec 3, 2005
    #2
    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. darrel
    Replies:
    2
    Views:
    2,238
    Alphonse Giambrone
    Mar 25, 2005
  2. Anubhav star

    Need help in javacript

    Anubhav star, May 4, 2008, in forum: HTML
    Replies:
    2
    Views:
    354
    Jukka K. Korpela
    May 5, 2008
  3. java with javacript

    , Sep 8, 2008, in forum: Java
    Replies:
    3
    Views:
    380
    Andrew Thompson
    Sep 8, 2008
  4. weiwei
    Replies:
    2
    Views:
    148
  5. Prashanth

    Replacing client side javacript

    Prashanth, Aug 6, 2003, in forum: Javascript
    Replies:
    2
    Views:
    119
    Lasse Reichstein Nielsen
    Aug 6, 2003
Loading...

Share This Page