unable to validate dynamically created fileupload control using javascript

Posted by Sbanda under JavaScript on 1/19/2012 | Points: 10 | Views : 2185 | Status : [Member] | Replies : 2
HI,
I have a requirement like whenever user clicks on add button then I need to create file upload control. So I have used below for creating control using JavaScript and it's working fine.
HTML code
<form id="form1" runat="server">
<table cellpadding="0" cellspacing="0" width="100%" border="0" id="mytable">
<tr id="Tr1" runat="Server">
<td colspan="2">
<asp:FileUpload ID="uploadPhoto1" runat="server" CssClass="" /><br />
<div id="Parent">
</div>
<input type="button" onclick="AddNewRow(); return false;" value="More" />&nbsp;
<asp:Button ID="btnAddPhoto" Text="add photo" runat="server" OnClick="btnAddPhoto_Click1"
OnClientClick="javascript:Test()" />&nbsp;
<asp:HiddenField ID="_hdnAdditionalScreenShots" runat="server" ClientIDMode="Static"
Value="1" />
</td>
</tr>
</table>
</form>

Javascript:
<script type="text/javascript">
function AddNewRow12() {
var additionalScreenShots = document.getElementById('_hdnAdditionalScreenShots');
var additionalScreenShotsNo = parseInt(additionalScreenShots.value);
var _upload = document.createElement("input")
_upload.setAttribute("type", "file")
_upload.setAttribute("ID", "_fulMobileAppScreen" + additionalScreenShotsNo)
_upload.setAttribute("runat", "server")
_upload.setAttribute("name", "uploads" + additionalScreenShotsNo)
var table = document.getElementById("mytable");
var td1 = document.createElement("td")
var i = $("#AddNewRow").index();
var tr = table.insertRow(i);
td1.className = "gray-table-text";
tr.className = "body-color";
td1.appendChild(_upload)
tr.appendChild(td1);
additionalScreenShots.value = additionalScreenShotsNo + 1;
}</script>

But I need to validate file type whenever user upload file using dynamically created file upload control. Can please help me on how to validate file type




Responses

Posted by: Blessyjees on: 1/19/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

I am not able to see the code for validation.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sbanda, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sbanda on: 1/19/2012 [Member] Starter | Points: 25

Up
0
Down
I don't know how to add validation for fileupload control in javascript

Sbanda, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response