Button in UpdatePanel triggers event, but the page doesn't update
标记如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <ContentTemplate> <form class="navbar-form pull-left"> <br /> </form> </ContentTemplate> <Triggers> </Triggers> </asp:UpdatePanel> <button id="Button1" runat="server" type="button" class="close" data-dismiss="alert">×</button> You shouldn't see this message! </asp:Panel> </asp:Panel> |
单击btnupload按钮时,服务器代码应该确定fileupload控件是否有文件。如果是这样,它会将面板控件的可见性更改为true。它在更新面板之外工作正常。
服务器代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | protected void btnUpload_Click(object sender, EventArgs e) { this.SetMessage(Message.Success); try { if (this.test.HasFile) { string filename = Path.GetFileName(GetUB04Doc.FileName); //test.SaveAs(Server.MapPath("~/") + filename); this.SetMessage(Message.Success); } } catch (Exception ex) { //TODO: Do something with th exception this.SetMessage(Message.Fail); } finally { //this.GetUB04Doc.Dispose(); } } private enum Message { Success, Fail } private void SetMessage(Message msg) { if (msg == Message.Success) { this.divAlert.InnerText ="Well done! The document appears to have uploaded successfully. Please wait..."; this.divAlert.Attributes.Add("class","alert alert-success"); } else { this.divAlert.InnerText ="Oh snap! Something broke. Please contact IT right away."; this.divAlert.Attributes.Add("class","alert alert-error"); } this.panAlert.Visible = true; } |
我也尝试将面板放入ContentTemplate部分,但结果是相同的。
对我在这里做错了什么有什么看法吗?
您应该围绕从另一个
1 2 3 | <ContentTemplate> <!-- .... |
代码后面:
1 2 3 | // ... this.panAlert.Visible = true; panAlertUpdatePanel.Update() |
旁注:正如@belogix已经评论过的那样,您应该在
MSDN:
Controls that Are Not Compatible with UpdatePanel Controls:
- …
FileUpload 和HtmlInputFile 控制何时用于作为异步回发的一部分上载文件。- …
To use a FileUpload or HtmlInputFile control inside an UpdatePanel
control, set the postback control that submits the file to be a
PostBackTrigger control for the panel. The FileUpload and
HtmlInputFile control can be used only in postback scenarios.
你需要把