473,587 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

register dynamic javacript with RegisterStartup Script

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.RegisterSt artupScript 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
Nov 20 '05 #1
1 1822
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

GenerateJavascr ipt()

And you have in a paging handler:
GetPage(e.NewPa geIndex)
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" <no@email.com > wrote in
news:OM******** ******@TK2MSFTN GP09.phx.gbl:
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.RegisterSt artupScript 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


--
Dec 3 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2357
by: propizzy | last post by:
Appreciate any help!!! PROBLEM: I have this form that allows the user to dynamically create additional fields (see javascript code bellow). I am trying to retrieve the values entered into these fields from my php script. I ultimatly need to pick out the variables and place the values into my php script page. I have worked with a little code I found on php.net (see php code below), but I wan unable to grasp the knowledge on how to...
1
2300
by: Wes Weems | last post by:
Hello, I currently have javascript and vbscript that needs to be spat out based on certain conditions in the codebehind. My vbscript code relies on the OnLoad event. However with the RegisterClientScriptBlock(), sticking the code in the form tags, I cant seem to get the bastard to work. Basically heres what I *NEED* to do. Generate some js and vbscript to be output before or after the form tags.
2
11410
by: Arjen | last post by:
Hello, I want that the client script is added at the and of the HTML output it is now at the beginning. Here is my code: private void Page_Load(object sender, System.EventArgs e) { RegisterClientScript(); }
1
1752
by: Darren Clark | last post by:
How does everyone register and access input objects on the client side? well... i suppose i am after some alternate ways... i use the following code to put the neccessary client javascript code so that i can then use them later... private void RegisterClientObjects() { System.Text.StringBuilder sBuild = new System.Text.StringBuilder();
3
7746
by: Hardy Wang | last post by:
Hi, By calling Page.RegisterClientScriptBlock, the JavaScript will be generated right after VIEWSTATE hidden field. Is there a way I can register my script to end of page instead beginning? -- WWW: http://hardywang.1accesshost.com ICQ: 3359839 yours Hardy
2
2848
by: darrel | last post by:
I have a page that I need to attach a javascript to the BODY tag when the page first loads (but not on postback). Is there a way to do that via codebehind? I've attached javascript to elements before like this: Form1.Attributes.Add("onSubmit", "myOnSubmitEventHandler();") But the problem is that there doesn't seem to be a
3
2276
by: Goh | last post by:
Hi, May I know how to register a java script inside the <head> tag not the body? I found only got method that able register at the body like RegisterStartupScript and RegisterClientScriptBlock. I would like to register this script inside user control. and this script must be run when the page is load. Got any method that able to call to solve this problem?
7
5240
by: AmitKu | last post by:
I'm trying to use RegisterStartupScript. I am making a call to it in Page_Load...and nothing shows up. Well that not's entirely true. Half the pages I've put it on do work properly, but the other half just don't work at all. Nothing shows up at all. How can I debug this? What are possible causes? Thanks,
3
21492
by: querry | last post by:
Hi all, I have a little problem, I want to register a javascript in a web page. I know it is done with the help of "Page.ClientScript.RegisterStartupScript()" method. But this methods accepts the javascript as a string as one of its parameters. My problem is to register the javascript file that is the .js file, which contains the javascript functions. Is there a way to do so??
0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.