按钮不会在ASP.NET中的updatepanel内部触发
问题描述:
我正在尝试使用updatepanel下的预览选项上传图片,没有updatepanel它工作正常但是当我应用更新面板时它不会被触发并在浏览器的开发者控制台中显示错误
我尝试过:
I'm trying to upload an image with preview option under updatepanel, without updatepanel it works fine but as I applied update panel it doesn't get fired and shows error in Browser's Developer Console
What I have tried:
<asp:UpdatePanel ID="upArtwork" runat="server" ChildrenAsTriggers="true" UpdateMode="Always">
<ContentTemplate>
<div class="form-group">
<label class="col-sm-2 control-label">Art Work</label>
<div class="col-sm-3">
<div class="input-group">
<asp:FileUpload ID="fileArtwork" runat="server" class="btn btn-default btn-file" />
</div>
</div>
<div class="col-sm-2">
<div class="input-group">
<asp:Button ID="btnArtworkPreview" runat="server" class="btn btn-warning" Text="Preview" OnClick="btnArtworkPreview_Click" />
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-sm-4">
<asp:Image ID="imgArtworkPreview" runat="server" Visible="false" Style="border: 1px solid #3c8dbc; padding: 5px; max-width: 200px" />
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger EventName="Click" ControlID="btnArtworkPreview" />
</Triggers>
</asp:UpdatePanel>
protected void btnArtworkPreview_Click(object sender, EventArgs e)
{
Stream strm = fileArtwork.PostedFile.InputStream;
BinaryReader reader = new BinaryReader(strm);
Byte[] bytes = reader.ReadBytes(Convert.ToInt32(strm.Length));
imgArtworkPreview.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes, 0, bytes.Length);
imgArtworkPreview.Visible = true;
}
错误:在开发者控制台中
ERROR: In Developer Console
Uncaught Error: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
at Function.Error$create [as create] (ScriptResource.axd:237)
at Sys$WebForms$PageRequestManager$_createPageRequestManagerServerError [as _createPageRequestManagerServerError] (ScriptResource.axd:656)
at Sys$WebForms$PageRequestManager$_parseDelta [as _parseDelta] (ScriptResource.axd:1534)
at Sys$WebForms$PageRequestManager$_onFormSubmitCompleted [as _onFormSubmitCompleted] (ScriptResource.axd:1314)
at Array.<anonymous> (ScriptResource.axd:47)
at ScriptResource.axd:3484
at Sys$Net$WebRequest$completed [as completed] (ScriptResource.axd:6376)
at XMLHttpRequest.Sys$Net$XMLHttpExecutor._onReadyStateChange (ScriptResource.axd:5996)
答
create [as create](ScriptResource.axd:237)
在Sys
create [as create] (ScriptResource.axd:237) at Sys
WebForms
PageRequestManager
PageRequestManager