ASP.NET How to use a counter with '<% =

I want to do multiple downloads, iam using some script from this forum. scripts work fine, but when I merge it with my project. javascript cannot get the value of my element. I found out the problem is that I have a lot of PANEL IDs on the page, I need to change to getElementByID('<%="FileUpdate.ClientID%>').value (original: getElementByID("FileUpdate").value )

PROBLEM: I need to use a counter, for example: getElementByID('<%="txtFileUpdate' + counter + '%>').value , but it CANNOT. The error says" too many characters in a character literal ", pointing to this line.

Please help, is there a solution to this problem?

Here is the script

-----> Error "for many characters in a character symbol"

  <script type="text/javascript" language="javascript"> var counter = 1; function AddFileUpload() { if (counter < 5) { counter++; var div = document.createElement('DIV'); div.innerHTML = '<input id="FileUpload' + counter + '" name = "file' + counter + '" type="file" />' + '<input id="Button' + counter + '" type="button" ' + 'value="Remove" onclick = "RemoveFileUpload(this)" />'; document.getElementById("FileUploadContainers").appendChild(div); } else { alert("Cannot attach more than 5 file"); } } function GetFile() { var temp; var error = ""; var stringx = ""; var exCounter = 1 ; for (exCounter; exCounter <= counter; exCounter++) { -----> stringx = document.getElementById('<%=FileUpload'+exCounter+'.ClientID%>').value; if (stringx != "") temp += stringx + "#;"; else error += exCounter + ", "; } if (error != "") { alert("Field " + error + " Still Empty"); return; } document.getElementById('<%=HiddenField1.ClientID%>').value = temp; } 
+4
source share
1 answer

Try the following:

 getElementByID('FileUpdate<%=counter%>').value 

or

 getElementByID('<%=txtFileUpdate + counter.ToString()%>').value 
0
source

Source: https://habr.com/ru/post/1439714/


All Articles