如何防止一个更新面板影响另一个C#ASP

问题描述

以下是我的问题,当我第一次使用第一个updatepanel的下拉列表正确运行时,它向我显示了隐藏的标签和文本框,一切正常。

但是,当我第一次使用dropProvince,州或地区时,它们会实现该方法

protected void 
droplistTipoIdentificacionDatosPropietario_SelectedindexChanged (object sender,EventArgs and )
{
    MessageBox.Show ("hello");
    this.datosPropietarioLblNumIdentificacion.Visible = true;
    this.datosPropietariotxtNumIdentificacion.Visible = true;
}

每滴墨滴都有自己的方法

protected void Page_Load(object sender,EventArgs e)
{
    if (!this.IsPostBack)
    {               
        this.datosPropietarioLblNumIdentificacion.Visible = false;
        this.datosPropietariotxtNumIdentificacion.Visible = false;
    }
}
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Label runat="server" Text="Tipo de Identificación"></asp:Label>
        <asp:DropDownList ID="droplistTipoIdentificacionDatosPropietario"
            runat="server" 
            Width="100%" 
            Height="30px"
            AutopostBack="true" 
            OnSelectedindexChanged="droplistTipoIdentificacionDatosPropietario_SelectedindexChanged">
            <asp:ListItem Text="Cédula Identidad" Value="C"></asp:ListItem>
            <asp:ListItem Text="Cédula de Residencia" Value="R"></asp:ListItem>
            <asp:ListItem Text="Cédula Jurídica" Value="J"></asp:ListItem>
            <asp:ListItem Text="Pasaporte" Value="P"></asp:ListItem>
        </asp:DropDownList>
    </ContentTemplate>
</asp:UpdatePanel>

通话背后的代码

protected void droplistTipoIdentificacionDatosPropietario_SelectedindexChanged(object sender,EventArgs e)
{
    MessageBox.Show("hola");
    this.datosPropietarioLblNumIdentificacion.Visible = true;
    this.datosPropietariotxtNumIdentificacion.Visible = true;
}
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <div class="grid3">
            <asp:Label runat="server" Text="Provincia"></asp:Label>
            <asp:DropDownList ID="droplistProvincia" 
                AutopostBack="true" onchange="testProvincia"
                OnSelectedindexChanged="droplistProvincia_SelectedindexChanged" 
                Width="100%" runat="server" Height="30px">
                <asp:ListItem Text="Seleccione"></asp:ListItem>
            </asp:DropDownList>
            <asp:Label runat="server" Text="Cantón"></asp:Label>
            <asp:DropDownList ID="droplistCanton" CssClass="item15" 
                AutopostBack="true" 
                OnSelectedindexChanged="droplistCanton_SelectedindexChanged" 
                Width="100%" runat="server" Height="30px">
                <asp:ListItem Text="Seleccione"></asp:ListItem>
            </asp:DropDownList>
            <asp:Label runat="server" CssClass="item16" Text="distrito"></asp:Label>
            <asp:DropDownList ID="droplistdistrito"
                AutopostBack="true" 
                OnSelectedindexChanged="droplistdistrito_SelectedindexChanged" 
                CssClass="item17"  runat="server" Height="30px">
                <asp:ListItem Text="Seleccione"></asp:ListItem>
            </asp:DropDownList>
        </ContentTemplate>
    </asp:UpdatePanel>

解决方法

您可能有复制/粘贴问题;有时复制/粘贴将不会执行代码。尝试从每个下拉列表中删除代码隐藏方法,然后重新添加它们。

<asp:DropDownList ID="droplistProvincia" 
    AutoPostBack="true" onchange="testProvincia"
    OnSelectedIndexChanged="droplistProvincia_SelectedIndexChanged" <- delete this
    Width="100%" runat="server" Height="30px">
    <asp:ListItem Text="Seleccione"></asp:ListItem>
</asp:DropDownList>

按上图所示删除该行,并删除后面的代码。双击下拉列表重新添加。

希望有帮助。很难从您的问题中分辨出问题所在。