Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Calling a Javascript function in a foreach loop

Reply
Thread Tools

Calling a Javascript function in a foreach loop

 
 
=?Utf-8?B?TWljcm9Nb3Ro?=
Guest
Posts: n/a
 
      07-06-2006
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
 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      07-06-2006
> 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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWljcm9Nb3Ro?=
Guest
Posts: n/a
 
      07-06-2006
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
>
>
>

 
Reply With Quote
 
=?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
Guest
Posts: n/a
 
      07-06-2006
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Problem with foreach loop =?Utf-8?B?SnVzdGlu?= ASP .Net 2 10-22-2004 08:35 AM
Re: foreach loop error Luc Kumps ASP .Net 0 08-22-2003 10:16 PM
Re: foreach loop error Kevin Spencer ASP .Net 0 08-22-2003 09:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57