我正在尝试使用带有类型文件的输入上传文件,如图所示
<div class="col-lg-12 col-sm-12 col-lg-xs col-md-12">
<table class="table-bordered table table-responsive" >
<tr class=" row form-group ">
<td class="text-center col-lg-4 col-sm-4 col-xs-4 col-xl-4">
<button onclick="triggerFileUpload()" class="btn btn-social btn-twitter" style="border-radius: 17px">
<span class="fa fa-camera"></span>
<div class="text-center"> image</div>
</button>
</td>
</tr>
</table>
</div>
</div>
<div class="form-group row">
<div class="col-lg-12 col-xs-12 col-sm-12 col-xs-12">
<input style="visibility: hidden;" type="file" runat="server" onchange="readURL(this);" id="ftp" accept="image/*|audio/*;capture=camera,microphone" class="form-control" />
<img id="blah" class="img-responsive img center-block" style="display: none" runat="server" src="#" />
</div>
</div>
使用
正确显示blah
中的所选文件
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#ContentPlaceHolder1_blah')
.attr('src', e.target.result)
//.width(150)
.css({ display: "block" })
//.height(200);
};
reader.readAsDataURL(input.files[0]);
}
initMap();
}
</script>
以及更新面板中的所有内容
<asp:UpdatePanel ID="uy" runat ="server" UpdateMode="Always" >
<ContentTemplate >
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID ="btnsave" />
<asp:PostBackTrigger ControlID="rblist" />
</Triggers>
</asp:UpdatePanel>
当我点击save button
时,始终发布的文件为null
,尽管我有页面加载
Page.Form.Attributes.Add("enctype", "multipart/form-data");