如何在没有回发的情况下填充第二个下拉列表?

时间:2015-02-24 12:33:45

标签: asp.net

我在一个页面中有很多下拉列表和文本框。我已经对文本框进行了验证。每个下拉列表都会填充另一个下拉列表。 问题是,当selectedindexchanged事件被触发时,所有现有的验证消息都会消失。如何在没有回发的情况下填充第二个下拉列表?

    <asp:Content ID="Content1" ContentPlaceHolderID="mainContentPlaceholder" runat="server">
    <asp:Panel ID="Panel1" runat="server" CssClass="formattingPanel" ScrollBars="Vertical">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true"  UpdateMode="Conditional" >
    <ContentTemplate>
    <table>
    <tr>
        <td>Title </td>
        <td><asp:DropDownList ID="ddlTitle" runat="server" OnSelectedIndexChanged="ddlTitle_SelectedIndexChanged" AutoPostBack="true" />
             <asp:TextBox ID="txtOther" runat="server" Visible="false" Text="" Width="33%"/>
        </td>
    </tr>
    <tr> 
        <td>  Nname </td>
        <td> <asp:TextBox ID="txtName" runat="server" /> </td>
    </tr>
       <tr>
        <td> Address1 </td>
        <td> <asp:TextBox ID="txtAddress1" runat="server" /> </td>
    </tr>
     <tr>
        <td> Address2 </td>
        <td> <asp:TextBox ID="txtAddress2" runat="server"/> </td>
    </tr>
          <tr>
        <td> Postcode </td>
        <td> <asp:TextBox ID="txtPostcode" runat="server" /> </td>
    </tr>
         <tr>
        <td> Telephone </td>
        <td> <asp:TextBox ID="txtTelephone" runat="server" /> 
             <asp:RegularExpressionValidator ID="regexTelephone" runat="server" ControlToValidate="txtTelephone" ErrorMessage ="* Numbers only & no spaces"
              ValidationExpression ="^\d+" ForeColor="Red"> </asp:RegularExpressionValidator>
         </td>
    </tr>
     <tr>
        <td> Email </td>
        <td> <asp:TextBox ID="txtEmail" runat="server" /> 
             <asp:RegularExpressionValidator ID="regexEmail" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" 
              ControlToValidate="txtEmail" ErrorMessage="* Invalid Email" ForeColor="Red" > </asp:RegularExpressionValidator>
        </td>
    </tr>
       <tr>
        <td>Title 1</td>
        <td> 
      <asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="true"  UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlType1" EventName="SelectedIndexChanged" />
            </Triggers>
            <ContentTemplate>
            <asp:DropDownList ID ="ddlType1" runat ="server"  OnSelectedIndexChanged="ddlType1_OnSelectedIndexChanged" AutoPostBack="true" /> 
            <asp:DropDownList ID ="ddlSubType1" runat ="server"  Visible="false" />
            </ContentTemplate>
        </asp:UpdatePanel>
        </td>
       </tr>
    <tr>        
        <td> Title 2 </td>
        <td>
        <asp:DropDownList ID ="ddlType2" runat ="server" OnSelectedIndexChanged="ddlType2_OnSelectedIndexChanged" AutoPostBack="true"/>
        <asp:DropDownList ID ="ddlSubType2" runat ="server"  Visible="false"/>
        </td>
    <tr>
    <tr>        
        <td> Title 3 </td>
        <td>
        <asp:DropDownList ID ="ddlType3" runat ="server" OnSelectedIndexChanged="ddlType3_OnSelectedIndexChanged" AutoPostBack="true"/>
        <asp:DropDownList ID ="ddlSubType3" runat ="server"  Visible="false"/>
        </td>
    <tr>
    ---- upto 8 dropdownlist sams as above      
     <tr>
        <td> <asp:Button ID="btnSave" runat="server" Text ="SAVE" OnClick="btnSave_Click"/> </td>
      </tr>
    </table>
 </ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
  </asp:Content>

我使用c#代码完成了ddl绑定..

0 个答案:

没有答案