0
ASP.NET 페이지에 컨트롤을 추가하려고합니다. 컨트롤이 성공적으로 추가되었지만 코드 뒤에서 액세스 할 수 없습니다. 아래 예제에서 Button1을 클릭하면 "업로드"(HttpFileCollection 유형)에 요소가 없습니다.jQuery를 사용하여 ASP.NET에 컨트롤 추가
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="add-remove-control.aspx.vb"
Inherits="APIU.Web.add_remove_control" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="_Assets/scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
var i = 1;
//allow only 3 elements
$('#add').click(function() {
if (i < 4) {
var add_input = '<input type="file" id="' + 'dynamic:' + i + '" name="' + 'dynamic:' + i + '" />'
var add_link = '<a href="#" class="remove">Remove</a>'
$('body').append('<p>' + add_input + add_link + '</p>');
i++;
}
});
$('.remove').live('click', function() {
$(this).parent('p').remove();
i--;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<a href="#" id="add">Add</a>
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<p>
</p>
</div>
</form>
</body>
</html>
코드 뒤에 :
여기에 내 마크 업의
"업로드"(유형 HttpFileCollection)에는 요소가 없습니다 왜Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim uploads As HttpFileCollection
uploads = HttpContext.Current.Request.Files
Dim sfile As String
For i As Integer = 0 To (uploads.Count - 1)
If (uploads(i).ContentLength > 0) Then
Dim c As String = System.IO.Path.GetFileName(uploads(i).FileName)
Try
uploads(i).SaveAs("C:\UploadedUserFiles\" + c)
sfile += uploads(i).FileName & "<br/>"
Catch Exp As Exception
End Try
End If
Next i
End Sub
?
이
'+ add_input + add_link + '
'); div에 컨트롤을 추가 할 수 있지만 컨트롤은 여전히 severside에 표시되지 않습니다. jQuery에서 runat = "server"속성을 추가하려고하면 마크 업이 렌더링되지 않고 오류가 발생합니다. – Narazana@Morron -'runat = "server"'에 대한 필요성은 다른 거래입니다. 당신의 폼은 잘못된 인코딩을 가지고있을 것입니다. 이것을 다음과 같이'