We help IT Professionals succeed at work.

create a for each loop for javascript in c#

Bran-Damage
Bran-Damage asked
on
359 Views
Last Modified: 2012-05-09
I need to create a for each loop for javascript in my c# code.

I have a list variable.  I want to pass this into my java script, and then when my java script gets fired off,  i want it to go through the list and do something.

Basically i need to iterate through the lstStrLabels list.  and during each iteration, i need to grab the string value out of it, and put it in the sprint.pagecreate(....) function and pImage will be the value that is in the element in the array for the current itteration.

I am building this string i c#, and then I am passing it to my registerstartupscript.
StrImage += "<script type=\"text/javascript\" language=\"javascript\">";
        StrImage += "var Sprint = document.getElementById(\"printdocument\");";
        StrImage += "var prname='" + subObj.strPrinterName + "';";
        StrImage += "var pImage='" + lstStrLabels + "';";
        StrImage += "var pNoCopies='" + subObj.iNoOfPrints.ToString() + "';";
        StrImage += "var Weg= SPrint.pagecreate(pImage, prname, pNoCopies);";
        StrImage += "</script>";

Open in new window

Comment
Watch Question

Adam MenkesC# ASP.NET Developer
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
C# ASP.NET Developer
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
This is what I am trying to do.  

Note: I am writing this in c# for java.


        StrImage += "<script type=\"text/javascript\" language=\"javascript\">";
        StrImage += "var x;";
        StrImage += "var SPrint = document.getElementById(\"printdocument\");";
        StrImage += "var lstStrLabels = '" + lstStrLabels + "';";
        StrImage += "var strPrinterName = '" + strPrinterName + "';";
        StrImage += "var iNoOfPrints = '" + iNoOfPrints + "';";
        StrImage += "for (x in lstStrLabels)";
        StrImage += "{";
        StrImage += "var Weg= SPrint.pagecreate(lstStrLabels[x], strPrinterName, iNoOfPrints);";
        StrImage += "}";
        StrImage += "</script>";

Open in new window

Author

Commented:
so this seems like it might be working, but I keep getting an error message when the java fires off that I have an Invalid character in a Base-64 string.

lstStrLabels is a list that I added a bunch of base-64 strings to.
Adam MenkesC# ASP.NET Developer
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
We are going to use a different route for this.  
Adam MenkesC# ASP.NET Developer
Top Expert 2010

Commented:
As the author pointed out in #33170778:
>>so this seems like it might be working, but I<<

The encoding is really a separate issue, and if the author decides to go another way rather than implementing a follow up suggestion, that is certainly an option, but should not negate that my solution was at least sufficient for the information as posted (originally).

Adam MenkesC# ASP.NET Developer
Top Expert 2010

Commented:
The solution I posted #33168202 would solve the (first) issue. I also followed up with 33171705 as a suggestion to fix any odd characters.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.