Link to home
Start Free TrialLog in
Avatar of Bran-Damage
Bran-DamageFlag for United States of America

asked on

create a for each loop for javascript in c#

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

SOLUTION
Avatar of Adam Menkes
Adam Menkes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bran-Damage

ASKER

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

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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
We are going to use a different route for this.  
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).

The solution I posted #33168202 would solve the (first) issue. I also followed up with 33171705 as a suggestion to fix any odd characters.