1
在發佈這個問題之前,我已經完成了我的研究,但我找不到任何有用的東西。我不知道是否有可能在jQuery的幫助下創建asp.net服務器控件。我有一個在服務器上運行的上傳控件輸入,並且在任何時候點擊某個特定按鈕時,我都使用JavaScript代碼創建新的上傳控件輸入。但我需要創建一個新的RegularExpressionValidator來控制每個新的上傳控件。這可以實現而不是使用多重上傳控制和我的頁面上的RegularExpressionValidator。仔細研究我迄今爲止所做的工作。使用jquery創建一個asp.net服務器控件
function addFileUploadBox() {
if (!document.getElementById || !document.createElement)
return false;
var uploadArea = document.getElementById("upload-area");
var count = uploadArea.getElementsByTagName("input").length;
if (!uploadArea)
return;
var newLine = document.createElement("br");
uploadArea.appendChild(newLine);
var newUploadBox = document.createElement("input");
// Set up the new input for file uploads
newUploadBox.type = "file";
newUploadBox.size = "20";
// The new box needs a name and an ID
if (!addFileUploadBox.lastAssignedId)
addFileUploadBox.lastAssignedId = 100;
newUploadBox.setAttribute("id", "dynamic" + addFileUploadBox.lastAssignedId);
newUploadBox.setAttribute("name", "dynamic:" + addFileUploadBox.lastAssignedId);
newUploadBox.setAttribute("runat", "server");
uploadArea.appendChild(newUploadBox);
$("<asp:RegularExpressionValidator ID='regular" + addFileUploadBox.lastAssignedId + "' ValidationExpression='(.*?)\.(jpg|jpeg|png|gif|JPG)$' runat='server' ErrorMessage='Invalid file' ControlToValidate='dynamic" + addFileUploadBox.lastAssignedId + "' ForeColor='Red'></asp:RegularExpressionValidator>").insertAfter("#dynamic" + addFileUploadBox.lastAssignedId);
addFileUploadBox.lastAssignedId++;
}
謝謝男人......我以爲這麼多。 – Oluwafemi