如何防止一个更新面板影响另一个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>

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

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...