2010-08-11 42 views
0

我在一個動態數據項目我的編輯頁面模板月底以下標記:如何在動態數據編輯頁面模板上獲取錯誤消息?

</asp:UpdatePanel> 
<br /> 
<asp:Label ID="errorLabel" runat="server" Visible="false" ForeColor="Red">Helloooo</asp:Label> 
<br /> 

而且我在代碼模板下面的代碼=背後:

protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e) 
{ 
    if (e.Exception != null & !e.ExceptionHandled) 
    { 
     errorLabel.Text = e.Exception.Message; 
     errorLabel.Visible = true; 
     return; 
    } 
    Response.Redirect(table.ListActionPath); 
} 

'if'條件成立,errorLabel.Visible = true等執行,但標籤在渲染屏幕上保持不可見。我究竟做錯了什麼?

回答

0

您的DetailsView位於UpdatePanel的內部,但您的錯誤標籤位於其外部。因此,UpdatePanel執行異步回發,並且錯誤標籤不會更新。 將錯誤標籤移動到UpdatePanel中應該可以解決您的問題。

<asp:Label id="errorLable" runat="server" Visible="false" ForeColor="Red" /> 
</asp:UpdatePanel>