【问题标题】:How to prevent one update panel from affecting another c# asp如何防止一个更新面板影响另一个 c# asp
【发布时间】:2020-09-04 01:12:20
【问题描述】:

我的问题如下,当我第一次使用第一个更新面板的下拉列表正常运行时,它显示了隐藏的标签和文本框,一切正常。

但是,当我第一次使用dropProvince,canton或region时,他们实现了该方法

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>

【问题讨论】:

    标签: c# webforms updatepanel


    【解决方案1】:

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

    <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>
    

    删除如上所示的行,同时删除代码隐藏。双击下拉列表重新添加。

    希望对您有所帮助。很难从你的问题中看出问题所在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 2012-12-14
      • 2017-09-05
      • 1970-01-01
      • 2018-11-10
      • 1970-01-01
      相关资源
      最近更新 更多