473,386 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Calling a Javascript function in a foreach loop

Hi,

I'm trying to call a Javascript function within a foreach loop. I am loop
over a series of users and I want to call the JS function which opens a new
window, passing in the user id to each call for the JS function.
So far I've done this:

foreach (USER _user in users)
{
string jscriptString = "<script language='JavaScript'>";
jscriptString += "pdfWinOpen(" + _user.userID + ");";
jscriptString += "</script>";

Response.Write(jscriptString);
}

But I can't seem to get the javascript to fire. File which opens in the new
window has a window.close(); in body onload method. So I easily close the
opened window.

How can I fire off the open window JS event?

Thanks

Stephen
Jul 6 '06 #1
3 3082
Hi,
>
I'm trying to call a Javascript function within a foreach loop. I am loop
over a series of users and I want to call the JS function which opens a new
window, passing in the user id to each call for the JS function.
So far I've done this:

foreach (USER _user in users)
{
string jscriptString = "<script language='JavaScript'>";
jscriptString += "pdfWinOpen(" + _user.userID + ");";
jscriptString += "</script>";

Response.Write(jscriptString);
}
Why a Response.Write? Careful: it doesn't mix well with the regular
asp.net way of building a page. See Page.RegisterStartupScript for a
better way. The Response.Write output will end up *before* the regular
output, where it *might* (not sure) be ignored by the browser.
>
But I can't seem to get the javascript to fire. File which opens in the new
window has a window.close(); in body onload method. So I easily close the
opened window.
So if I understand correctly, that new window closes itself
immediately?
>
How can I fire off the open window JS event?

Thanks

Stephen
What do you see in the html source of the page that should contain this
javascript? Does the javascript you expect exist? Does it look OK?
Any script warnings?

Hans Kesting
Jul 6 '06 #2
Hi,

Thanks for the help, after taking about this here, we've decided that we
might have to create a small WIndows Form app which open a mini browser
calling my generate PDF page for each user.

Stephen

"Hans Kesting" wrote:
Hi,

I'm trying to call a Javascript function within a foreach loop. I am loop
over a series of users and I want to call the JS function which opens a new
window, passing in the user id to each call for the JS function.
So far I've done this:

foreach (USER _user in users)
{
string jscriptString = "<script language='JavaScript'>";
jscriptString += "pdfWinOpen(" + _user.userID + ");";
jscriptString += "</script>";

Response.Write(jscriptString);
}

Why a Response.Write? Careful: it doesn't mix well with the regular
asp.net way of building a page. See Page.RegisterStartupScript for a
better way. The Response.Write output will end up *before* the regular
output, where it *might* (not sure) be ignored by the browser.

But I can't seem to get the javascript to fire. File which opens in the new
window has a window.close(); in body onload method. So I easily close the
opened window.

So if I understand correctly, that new window closes itself
immediately?

How can I fire off the open window JS event?

Thanks

Stephen

What do you see in the html source of the page that should contain this
javascript? Does the javascript you expect exist? Does it look OK?
Any script warnings?

Hans Kesting
Jul 6 '06 #3
Hans Kesting wrote:
Why a Response.Write? Careful: it doesn't mix well with the regular
asp.net way of building a page. See Page.RegisterStartupScript for a
better way. The Response.Write output will end up *before* the regular
output, where it *might* (not sure) be ignored by the browser.
Historically, Javascript has been used anywhere in the pages, so
browsers are quite patient with less nicely formed pages. It will
probably run the script wherever it is.

However, the script uses the function "pdfWinOpen". If that function is
not written to the page *before* the calls are written, it will not
exist when the calls are executed.
Jul 6 '06 #4

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

Similar topics

2
by: Jens Körte | last post by:
Hi! I've got a typical newbie-problem, I guess. I got some selectboxes on my site. these boxes get their data from a databse. everything works fine, but when a user selects a value from one of...
5
by: Andy Sutorius | last post by:
Hi, I am attempting to convert this vb function to csharp but I am getting stuck on the if statement dt.Rows(iLoop)("FAQCategoryID")). The compiler says "method name expected" and underlines...
13
by: TrintCSD | last post by:
How can I reset the collections within a foreach to be read as a change from within the foreach loop then restart the foreach after collections has been changed? foreach(string invoice in...
3
by: phl | last post by:
hi, I have a number of usercontrols which inherits a interface. the function in this interface is used to provide information about the usercontrol. I would like to call this function say when a...
4
by: Adam Smith | last post by:
Hello, How can I call or trigger an external javascript twice in a form? I have <script language="JavaScript" src="country_state.js" name="Country_State"> <script type="text/javascript"...
16
by: deepres | last post by:
Hi, I have the following problem. In my application I'm dynamically replacing some of web-page content. For example, I have something like that: <span id="ui_tr_22_1_treeJ_span" > <div...
4
by: dannyboy | last post by:
Hi I'm trying to echo some php into a piece of javascript that checks that the selectedIndex in a given select name is not 0, and gives an alert if this is so: //// <script...
3
by: SM | last post by:
Hello, I have an array that holds images path of cd covers. The array looks like this: $cd = array( 589=>'sylver.jpg', 782=>'bigone.jpg', 158=>'dime.jpg' );
9
by: mrcheeky | last post by:
Hi, I'm stuck, but it's almost working! From a html page, my javascript calls a server-side php script. The php reads a value from a server-side .txt file and passes it back as a javascript...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.