2014-01-26 32 views
0

當我檢查rbEmployee時,回發發生,但它不適用於rbBatch。爲什麼如此。PostBack不發生單選按鈕

ASPX:

<asp:RadioButton ID="rbBatch" runat="server" Text="Batch" GroupName="OB" 
CausesValidation="false" AutoPostBack="true" 
OnCheckedChanged="rbBatch_CheckedChanged"/> 

<asp:RadioButton ID="rbEmployee" runat="server" Text="Employee" GroupName="OB" 
CausesValidation="false" AutoPostBack="true" 
OnCheckedChanged="rbEmployee_CheckedChanged"/> 

<asp:UpdatePanel runat="server" UpdateMode="Conditional"> 
<Triggers> 
    <asp:AsyncPostBackTrigger ControlID="rbBatch" EventName="CheckedChanged"/> 
    <asp:AsyncPostBackTrigger ControlID="rbEmployee" EventName="CheckedChanged"/> 
</Triggers> 
<ContentTemplate> 
    <asp:GridView ID="gvBatch" runat="server"></asp:GridView> 
    <asp:GridView ID="gvMain" runat="server" visible="false"></asp:GridView> 
</ContentTemplate> 
</asp:UpdatePanel> 

C#:

protected void rbBatch_CheckedChanged(object sender, EventArgs e) 
{ 
    if(rbBatch.Checked) 
    { 
    gvBatch.visible=true; 
    gvMain.visible=false; 
    } 
} 

protected void rbEmployee_CheckedChanged(object sender, EventArgs e) 
{ 
    if(rbEmployee.Checked) 
    { 
    gvBatch.visible=false; 
    gvMain.visible=true; 
    } 
} 
+0

你是如何在代碼中的'PostBack'事件 – bjan

+0

斷點背後 – Ruby

回答

1

AsyncPostBack觸發器只能在UpdatePanel中使用,所以將RadioButtons移動到UpdatePanel並重試。

+0

工作。謝謝。任何理由,爲什麼它只爲其中一個按鈕工作? – Ruby

+0

@Ruby異步回傳觸發器只能與更新面板一起使用 – techno

+0

我認爲他也應該實現我的解決方案(與您的解決方案) – 2014-01-26 08:26:44

0

您是否嘗試過的CausesValidation = 「真」?

+0

檢查是。它沒有工作。 – Ruby

0

這是因爲當您選擇A時,B的事件不會觸發(除非最近被選中)。

更好的解決方案如下:

protected void rbBatch_CheckedChanged(object sender, EventArgs e) 
{ 
    handle(); 
} 

protected void rbEmployee_CheckedChanged(object sender, EventArgs e) 
{ 
    handle(); 
} 

private void handle() 
{ 
    if(rbBatch.Checked) 
    { 
    gvBatch.visible=true; 
    gvMain.visible=false; 
    } 
    else if(rbEmployee.Checked) 
    { 
    gvBatch.visible=false; 
    gvMain.visible=true; 
    } 
} 
+0

不用它這樣工作。 – Ruby