2012-12-06 120 views
0

我有一箇中繼器,其中包含每個項目中的單選按鈕,以及更新面板中的整個事件站點。當我選擇一個單選按鈕時,整個頁面會重新加載。爲什麼它不只是更新更新面板。我已經將它簡化爲一個非常簡單的例子,以避免混亂。代碼在這裏...ASP.Net AJAX UpdatePanel不能與Repeater和RadioButtons一起工作

ASPX ...

<asp:ScriptManager ID="SM1" runat="server" /> 
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional"> 
    <ContentTemplate> 
     <asp:Repeater runat="server" ID="history"> 
      <ItemTemplate> 
       <asp:RadioButton runat="server" ID="radioButton" AutoPostBack="true" GroupName="HistoryGroup" OnCheckedChanged="RadioButton_CheckChanged" /><br /> 
      </ItemTemplate> 
     </asp:Repeater> 

     <p><asp:Literal runat="server" ID="output" /></p> 
    </ContentTemplate> 
</asp:UpdatePanel> 

代碼...

public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!Page.IsPostBack) 
     { 
      List<int> list = new List<int>(); 
      for (int i = 0; i < 20; i++) 
       list.Add(i); 
      history.DataSource = list.ToArray(); 
      history.DataBind(); 
     } 
    } 

    protected void RadioButton_CheckChanged(Object sender, EventArgs e) 
    { 
     output.Text = DateTime.Now.ToString(); 
    } 
} 
+0

嘗試刪除「UpdateMode =」有條件「並進行測試 – Sunny

+0

這對我來說不起作用,whoel頁面仍然會重新加載 – Mottster

回答

0

原來的解決方案是從單選按鈕刪除組名觸發。當我刪除這個標籤時,它會異步觸發並更新面板。無論如何,我實際上不需要這個標籤(由於已知的Bug,其中GroupName在Repeater中的RadioButtons上不起作用),因爲我在我的單擊事件中處理分組(即,取消選中其他中繼器項目中的其他同名RadioButton) 。

0

請加up1.Update()在output.Text = Dat之後eTime.Now.ToString()。您的單選按鈕不是的UpdatePanel