2014-09-26 33 views
0

我有一個表格已經工作了很長時間,今天只是失敗,我的UAT數據庫。不同的數據ASP.Net綁定問題

查看:

<%@ Control /* ... */ %> 
<asp:Panel runat="server"> 

    <!-- Area not visible, list disabled --> 
    <asp:PlaceHolder runat="server" Visible='False'> 
     <asp:RadioButtonList runat='server' id='lstTradingSameAsRegistered' 
      AutoPostBack="True" Enabled="False" /> 
    </asp:PlaceHolder> 

    <asp:PlaceHolder runat="server" Visible='<%#!GetCurrentValue(IsTradingAddressSameAsRegistered , lstTradingSameAsRegistered)%>'> 
     <!-- ... --> 
    </asp:PlaceHolder> 

    <-- Area visible, list enabled --> 
    <asp:PlaceHolder runat="server" Visible='True'> 
     <asp:RadioButtonList runat='server' id='lstHeadOfficeSameAsRegisteredLabel' 
      AutoPostBack="True" Enabled="True" /> 
    </asp:PlaceHolder> 

    <asp:PlaceHolder runat="server" Visible='<%#!GetCurrentValue(IsHeadOfficeAddressSameAsRegistered , lstHeadOfficeSameAsRegistered)%>'> 
     <!-- ... --> 
    </asp:PlaceHolder> 

</asp:Panel> 

代碼隱藏:

protected override void OnInit(EventArgs e) 
{ 
    base.OnInit(e); 

    lstTradingSameAsRegistered.Items.Clear(); 
    lstTradingSameAsRegistered.Items.Add("Yes", "True"); 
    lstTradingSameAsRegistered.Items.Add("No", "False"); 

    lstHeadOfficeSameAsRegistered.Items.Clear(); 
    lstHeadOfficeSameAsRegistered.Items.Add("Yes", "True"); 
    lstHeadOfficeSameAsRegistered.Items.Add("No", "False"); 

    if (!IsPostBack) 
    { 
     lstTradingSameAsRegistered.SelectedIndex = IsTradingAddressSameAsRegistered ? 0 : 1; 
     lstHeadOfficeSameAsRegistered.SelectedIndex = IsHeadOfficeAddressSameAsRegistered ? 0 : 1; 
    } 
} 

public bool? GetCurrentValue(bool modelValue, ListControl control) 
{ 
    if (IsPostBack) 
    { 
     var result = Request.Form[control.UniqueID].TryParseAs<bool>(); 
     if (result.HasValue) 
      return result; 

     if (control.SelectedValue == "True") 
      return true; 

     if (control.SelectedValue == "False") 
      return false; 

     return null; 
    } 
    else return modelValue; 
} 

在開發+直播數據庫的代碼工作正常,但在UAT我就打電話GetCurrentValue()後得到NullReferenceException一個PostBack

當我在lstHeadOfficeSameAsRegisteredLabel選擇一個新項目時,一個PostBack事件引發並在視圖兩個RadioButtonList的所選擇的項目是null

該項目的源代碼是相同的,在我的測試過程中,我只更改配置文件中的數據庫路徑。在調試頁面時我沒有遇到任何其他錯誤。

由於這只是綁定(我猜),可能是什麼問題,以及如何解決它?

+0

確保您在兩個DB中都有相同的數據。可能有一些數據丟失。 – Mairaj 2014-09-27 03:58:08

+0

除了此特定頁面的ID數據相同外。如果有一些數據我應該得到一個不同的錯誤信息,應該發生在我的數據層。相反,我的'RadioButtonList'包含靜態數據沒有綁定。 – glautrou 2014-09-27 12:50:24

+0

嗯,我看不到任何數據訪問在這裏。你似乎缺少一些代碼 - 你可以更新你的問題,並提供'IsTradingAddressSameAsRegistered'和'IsHeadOfficeAddressSameAsRegistered'(這些看起來像屬性,也許這是一些數據訪問發生的地方?)代碼 – sh1rts 2014-10-02 01:52:18

回答

0

該問題來自框架。我有一個自定義的DateTime' class in my application created to avoid to change the server date, and when this date is setted to the future that breaks the .Net binding in some parts of my application. I don't have the entire source code of the framework so I cannot investigate more, but setting my custom date the same value as DateTime`修復了這個問題。