I am attempting to create asp.net elements on the fly using javascript. I can successfully create html elements on the fly like so
var _upload = document.createElement("input");
_upload.setAttribute("type", "file");
_upload.setAttribute("ID", "upload" + rownum);
_upload.setAttribute("runat", "server");
_upload.setAttribute("name", "uploads" + rownum);
A few questions:
-
Is this the equivalent to the asp.net FileUpload control?
-
How can I create the exact asp.net controls in javascript?
What can an asp.net fileupload do that my control I created above cannot do if anything?
Florians idea is useful, but (depending on your case of course) there may be an even simpler fix: create the fileupload control when rendering the page but put in inside a hidden div. Then all you have to do in JavaScript is show the div.
Some example code (asp.net controls may be wrong, it’s been a while since I used them):
mypage.aspx:
style.css
mypage.js