2013-08-29 62 views
0

我有兩個DropdownList。我想綁定第一個選擇變化的第二個。在asp.net更新面板中的AsyncPostBackTrigger後Dropdownlist值損失

這裏是我的代碼:

<asp:ScriptManager ID="ScriptManager1" runat="server" /> 
<asp:UpdatePanel ID="upCategory" runat="server" UpdateMode="Conditional"> 
    <ContentTemplate> 
     <asp:MultiView ID="mvSuggestions" ActiveViewIndex="0" runat="server"> 
      <asp:View ID="vManageCategory" runat="server"> 
       <table width="100%"> 
        <tr> 
         <td style="text-align:center;"> <span class="BlockHeader"><span>Suggestions</span></span> 
         </td> 
        </tr> 
        <tr> 
         <td> <span class="ButtonInput"> 
        <span>    

        <asp:Button ID="btnCreateNew" runat="server" TabIndex="2" 
      Text="Create New Suggestions" onclick="btnCreateNew_Click" /> 


        </span></span> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          <asp:GridView ID="gvSuggestion" runat="server" AllowPaging="true" AutoGenerateColumns="false" DataKeyNames="id" Width="285px"> 
           <Columns> 
            <asp:boundfield datafield="suggestion_area" headertext="Suggestions" /> 
            <asp:boundfield datafield="active_closed" headertext="status" /> 
            <asp:boundfield datafield="date_creation" headertext="created date" /> 
           </Columns> 
          </asp:GridView> 
         </td> 
        </tr> 
       </table> 
      </asp:View> 
      <asp:View ID="vCreateSuggestions" runat="server"> 
       <table width="100%"> 
        <tr> 
         <td colspan="2" style="text-align:center;"> <span class="BlockHeader"><span>Suggestions</span></span> 
         </td> 
        </tr> 
        <tr> 
         <td colspan="2"> <span class="ButtonInput"> 
        <span>         
        <asp:Button ID="btnShowCategory" runat="server" TabIndex="2" 
      Text="Show Suggestions" onclick="btnShowCategory_Click" />   
        </span></span> 
         </td> 
        </tr> 
        <tr> 
         <td rowspan="2">Suggestion Subject</td> 
         <td rowspan="2"> 
          <asp:TextBox ID="txtSuggestionSubject" runat="server" TextMode="MultiLine"></asp:TextBox> 
          <asp:RequiredFieldValidator ID="rfvSuggestionSubject" runat="server" ControlToValidate="txtSuggestionSubject" ValidationGroup="Blank" ErrorMessage="Category can not blank!" Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator> 
          <ajaxToolkit:ValidatorCalloutExtender ID="vceSubCategory" TargetControlID="rfvSuggestionSubject" runat="server" Width="120px"></ajaxToolkit:ValidatorCalloutExtender> 
         </td> 
        </tr> 
        <tr> 
         <td></td> 
         <td></td> 
        </tr> 
        <tr> 
         <td> 
          <asp:Label ID="lblCategory" runat="server" Text="Category"></asp:Label> 
         </td> 
         <td>** 
          <asp:DropDownList ID="ddlCategory" runat="server" Height="16px" ValidationGroup="Blank" OnSelectedIndexChanged="ddlCategory_SelectedIndexChanged" Width="210px" AutoPostBack="true"></asp:DropDownList>** 
          <asp:RequiredFieldValidator ID="rfvCategory" runat="server" ControlToValidate="ddlCategory" ValidationGroup="Blank" ErrorMessage="Please select category!" Display="None" InitialValue="0" SetFocusOnError="true"></asp:RequiredFieldValidator> 
          <ajaxToolkit:ValidatorCalloutExtender ID="cveCategory" TargetControlID="rfvCategory" runat="server" Width="230px"></ajaxToolkit:ValidatorCalloutExtender> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          <asp:Label ID="lblSubCategory" runat="server" Text="Sub Category"></asp:Label> 
         </td> 
         <td> 
          <asp:DropDownList ID="ddlSubCategory" runat="server" Width="203px"></asp:DropDownList> 
          <asp:RequiredFieldValidator ID="rfvSubCategory" runat="server" ControlToValidate="ddlSubCategory" ValidationGroup="Blank" ErrorMessage="Please select sub category!" Display="None" InitialValue="0" SetFocusOnError="true"></asp:RequiredFieldValidator> 
          <ajaxToolkit:ValidatorCalloutExtender ID="cveSubCategory" TargetControlID="rfvSubCategory" runat="server" Width="230px"></ajaxToolkit:ValidatorCalloutExtender> 
         </td> 
        </tr> 
        <tr> 
         <td rowspan="2">Suggestion</td> 
         <td rowspan="2"> 
          <asp:TextBox ID="txtSuggestion" runat="server" TextMode="MultiLine" Height="75px"></asp:TextBox> 
          <asp:RequiredFieldValidator ID="rfvSuggestion" runat="server" ControlToValidate="txtSuggestion" ValidationGroup="Blank" ErrorMessage="Suggestion can not blank!" Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator> 
          <ajaxToolkit:ValidatorCalloutExtender ID="vceSuggestion" TargetControlID="rfvSuggestion" runat="server" Width="120px"></ajaxToolkit:ValidatorCalloutExtender> 
         </td> 
        </tr> 
        <tr> 
         <td></td> 
         <td></td> 
        </tr> 
        <tr> 
         <td></td> 
         <td></td> 
        </tr> 
        <tr> 
         <td></td> 
         <td></td> 
        </tr> 
        <tr> 
         <td align="right" colspan="2" style=" padding-right:150px;"> <span class="ButtonInput"><span> 
      <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" 
       TabIndex="2" Text="Submit" ValidationGroup="Blank" /> 
      </span></span> 
         </td> 
        </tr> 
       </table> 
      </asp:View> 
     </asp:MultiView> 
    </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="btnCreateNew" EventName="click" /> 
     <asp:AsyncPostBackTrigger ControlID="btnShowCategory" EventName="click" /> 
     <asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="click" />** 
     <asp:AsyncPostBackTrigger ControlID="ddlCategory" EventName="SelectedIndexChanged" />**</Triggers> 
</asp:UpdatePanel> 

當我改變了下拉列表ddlCategory,在下拉列表ddlCategory失去了它的價值,並顯示空白,也不會觸發SelectionIndexChanged事件。

回答

0

更新面板內的控件默認會觸發異步調用。你不需要任何東西。並且AsyncPostBackTrigger用於UpdatePanel之外的控件觸發異步回發,這不是您的情況。所以刪除下列行:

<asp:AsyncPostBackTrigger ControlID="btnCreateNew" EventName="click" /> 
<asp:AsyncPostBackTrigger ControlID="btnShowCategory" EventName="click" /> 
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="click" /> 
<asp:AsyncPostBackTrigger ControlID="ddlCategory" EventName="SelectedIndexChanged" /> 

爲了更好地理解我建議閱讀AsyncPostBackTrigger vs PostBackTriggerWhat is the different between AsyncPostBackTrigger & PostBackTrigger really?

相關問題