1

在发布这个问题之前我已经完成了我的研究,我找不到任何有用的东西。我不知道是否可以在 jquery 的帮助下创建 asp.net 服务器控件。我有一个在服务器上运行的上传控制输入,并且我使用了一个 javascript 代码来创建一个新的上传控制输入,只要单击一个特定的按钮。但是我需要创建一个新的RegularExpressionValidator来控制每个新的上传控件。这可以实现,而不是在我的页面上使用多个上传控件和RegularExpressionValidator 。仔细检查我到目前为止所做的代码。

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++;
}
4

1 回答 1

4

这是不可能的。

原因:Asp.net 将其从 xhtml 转换为它的输出服务器端。

Anything you have done via jquery or javascript will be done client-side. The server knows nothing about validator that you have just attempted to create.

于 2012-12-21T01:28:09.653 回答