Oluwafemi
Oluwafemi

Reputation: 14889

Creating an asp.net server control with jquery

I have done my research before posting this question and I can not find anything helpful. I do not know if it is possible to create asp.net server control with the help of jquery. I have an upload control input that runs at server and I have used a javascript code to create a new upload control input any time a particular button is clicked. But I require a new RegularExpressionValidator to be created to control each new upload control. Can this be achieved rather than using multple upload control and RegularExpressionValidator on my page. Scrutinize my code on what I have done so far.

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

Upvotes: 1

Views: 716

Answers (1)

Khan
Khan

Reputation: 18162

This is not possible.

Reason: Asp.net does its conversion from xhtml to its output server-side.

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.

Upvotes: 4

Related Questions