Inquiridor
Controle Executando eventos de outros controle.

Pergunta
-
Caros colegas, alguém sabe me informar como configurar o controle para que ele execute somente o evento pertencente a ele?
Por exemplo: Eu seleciono um item no DropDownList e um evento é disparado
Quando eu seleciono outro item em outra DropDownList na mesma página, primeiro é disparado o evento da primeira DropDownList para em seguida executar o evento da segunda DropDownList quando deveria ser executado somente o evento da segunda DropDownList.
Private Sub cod_nivel1_ni1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cod_nivel1_ni1.SelectedIndexChanged
Session("cod_nivel1_ni1") = cod_nivel1_ni1.SelectedValue
End SubPrivate Sub Ano_TextChanged(sender As Object, e As EventArgs) Handles Ano.TextChanged
Session("AnoRes") = Ano.TextobjGeracaoResiduo.IndicadoresSSMAGerarDados(cod_nivel1_ni1.SelectedValue, Ano.Text)
End SubGrato
- Editado Oliciel Cortes segunda-feira, 26 de dezembro de 2016 05:45
Todas as Respostas
-
Você deve ter mantido selecionado mais de um controle quando adicionou o event handler. O comportamento normal é disparar para apenas o controle que estava selecionado quando adicionou o tratamento para o evento.
Faça uma varredura em seu código pois outros controles devem estar fazendo referência explícita ao mesmo método.
If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".
Se achou este post útil, por favor clique em "Votar como útil". Se por acaso respondeu sua dúvida, lembre de "Marcar como Resposta".
-
Juliano obrigado pela pronta resposta, creio que seja algo de configuração e não sei onde alterar, pois esse problema apareceu recentemente e está acontecendo em todas as páginas.
Aqui está o código da página onde identifiquei o problema.
Se estiver ao seu alcance em ajudar ficarei grato.
Partial Class Contrate_res_admin_RESIndicadoresSSMAMensalV1
Inherits System.Web.UI.Page#Region "Geração Residuos"Private objGeracaoResiduo As New Contrate.RES.DsAdmin.GeracaoResiduo#End Region#Region " Load "Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("num_matricula_usr") = Nothing Then
Response.Redirect("~/Default.aspx")
End IfIf Not Page.IsPostBack Then
cod_nivel1_ni1.SelectedValue = IIf(Session("cod_nivel1_ni1") Is Nothing, "-1", Session("cod_nivel1_ni1"))
cod_nivel1_ni1.DataBind()Ano.Text = IIf(Session("AnoRes") Is Nothing, "", Session("AnoRes"))End IfEnd Sub#End Region#Region " Grid "Private Sub grvPrincipal_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles grvPrincipal.RowCreated
If e.Row.RowType = ListItemType.AlternatingItem Or e.Row.RowType = ListItemType.Item Then
e.Row.Attributes.Add("onMouseOver", "selecionaGrid(this)")
e.Row.Attributes.Add("onMouseOut", "deSelecionaGrid(this)")
e.Row.Style("cursor") = "hand" ' Cursor
End If
End SubPrivate Sub grvPrincipal_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles grvPrincipal.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If Ano.Text <> "" ThenIf e.Row.DataItem("Descricao") = "I - Perigoso" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg"
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 0)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "IIA - Não Inertes" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg"
'e.Row.BackColor = Drawing.Color.Red
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 0)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "IIB - Inertes" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg"
'e.Row.BackColor = Drawing.Color.Red
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 0)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "Aterro Sanitário" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg"
'e.Row.BackColor = Drawing.Color.Red
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 0)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "Aterro Industrial" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg"
'e.Row.BackColor = Drawing.Color.Red
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 0)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "Co-processamento" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg"
'e.Row.BackColor = Drawing.Color.Red
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 0)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "Incineração" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg"
'e.Row.BackColor = Drawing.Color.Red
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 0)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "Reciclagem" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg"
'e.Row.BackColor = Drawing.Color.Red
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 0)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "Re-refino" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg"
'e.Row.BackColor = Drawing.Color.Red
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 0)
Else
e.Row.Cells(i).Text = "---"
End If
NextElseIf e.Row.DataItem("Descricao") = "Geração Total" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg"
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#DAFFFF")
e.Row.Font.Bold = True
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 0)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "%Reaproveitamento" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "%"
e.Row.Font.Bold = True
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#DAFFFF")
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 2)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "%Rejeito" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "%"
e.Row.Font.Bold = True
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#DAFFFF")
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 2)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "Indicador" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg/t"
e.Row.Font.Bold = True
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#DAFFFF")
e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 2)
Else
e.Row.Cells(i).Text = "---"
End If
Next
ElseIf e.Row.DataItem("Descricao") = "Produção" Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).Text = "kg"
'e.Row.Font.Bold = True
'e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#DAFFFF")
'e.Row.HorizontalAlign = HorizontalAlign.Center
For i As Integer = 2 To e.Row.Cells.Count - 1
If Not e.Row.Cells(i).Text.Equals(" ") Then
e.Row.Cells(i).Text = FormatNumber(Convert.ToDouble(e.Row.Cells(i).Text), 0)
Else
e.Row.Cells(i).Text = "---"
End If
Next
End If
End If
End If
End Sub
#End Region#Region "Ddls"Private Sub cod_nivel1_ni1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cod_nivel1_ni1.SelectedIndexChanged
Session("cod_nivel1_ni1") = cod_nivel1_ni1.SelectedValueEnd SubPrivate Sub Ano_TextChanged(sender As Object, e As EventArgs) Handles Ano.TextChanged
Session("AnoRes") = Ano.TextobjGeracaoResiduo.IndicadoresSSMAGerarDados(cod_nivel1_ni1.SelectedValue, Ano.Text)
End Sub#End Region#Region "Botões"
Private Sub btnFechar_Click(sender As Object, e As EventArgs) Handles btnFechar.Click
Response.Redirect("Principal.aspx")
End Sub#End RegionEnd Class -
Pelo aspx não está sendo associado o evento (via atributos de tags)? Verifique se há algum JavaScript tratando o evento do dropdown e disparando uma mudança na seleção incorretamente.
If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".
Se achou este post útil, por favor clique em "Votar como útil". Se por acaso respondeu sua dúvida, lembre de "Marcar como Resposta".
-
Na verdade o JavaScript está tratando o TextBox.
Segue o código.
<%@ Page Title="" Language="VB" MasterPageFile="~/Contrate.RES/admin/MasterPageRES.master" AutoEventWireup="false" CodeFile="RESIndicadoresSSMAMensalV1.aspx.vb" Inherits="Contrate_res_admin_RESIndicadoresSSMAMensalV1" MaintainScrollPositionOnPostback="true" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript" language="javascript">
function onCalendarShown() {
var cal = $find("calendar1");
cal._switchMode("years", true);
if (cal._yearsBody) {
for (var i = 0; i < cal._yearsBody.rows.length; i++) {
var row = cal._yearsBody.rows[i];
for (var j = 0; j < row.cells.length; j++) {
Sys.UI.DomEvent.addHandler(row.cells[j].firstChild, "click", call);
}
}
}
}function onCalendarHidden() {
var cal = $find("calendar1");
if (cal._yearsBody) {
for (var i = 0; i < cal._yearsBody.rows.length; i++) {
var row = cal._yearsBody.rows[i];
for (var j = 0; j < row.cells.length; j++) {
Sys.UI.DomEvent.removeHandler(row.cells[j].firstChild, "click", call);
}
}
}
}function call(eventElement) {
var target = eventElement.target;
switch (target.mode) {
case "year":
var cal = $find("calendar1");
cal.set_selectedDate(target.date);
cal._blur.post(true);
cal.raiseDateSelectionChanged(); break;
}
}
</script>
<asp:UpdatePanel ID="upnPrincipal" runat="server">
<ContentTemplate>
<table style="width: 100%">
<tr>
<td style="width: 40px;">
</td>
<td>
<table>
<tr>
<td>
<img id="Img2" runat="server" alt="" src="../../img/seta_titulo.png" width="20" />
</td>
<td>
<asp:Label ID="lblTitulo" SkinId="lblForm" runat="server" EnableViewState="False" Height="16px">Indicadores Mensal SSMA</asp:Label></td>
</tr>
</table>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<table id="tablePrincipal" runat="server">
<tr>
<td>
<asp:Label id="Label4" runat="server">Empresa:</asp:Label>
</td>
<td style="width: 650px;">
<asp:DropDownList ID="cod_nivel1_ni1" runat="server" AppendDataBoundItems="True" AutoPostBack="True" EnableViewState="False" DataSourceID="odsListarNivel1" DataTextField="des_razao_social_ni1" DataValueField="cod_nivel1_ni1">
<asp:ListItem Value="-1">Selecione</asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource id="odsListarNivel1" runat="server" TypeName="Contrate.EMA.DsAdmin.Nivel1" SelectMethod="ListarNivel1PorUsuario" InsertMethod="IncluirNivel1Arquivo" OldValuesParameterFormatString="original_{0}">
<InsertParameters>
<asp:Parameter Name="cod_nivel1_ni1" Type="Int32" />
<asp:Parameter Name="num_ano_nia" Type="Int64" />
<asp:Parameter Name="des_arquivo_inventario_ni1" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:SessionParameter Name="cod_usuario_usr" SessionField="cod_usuario_usr" Type="Int32" />
<asp:SessionParameter Name="cod_modulo_gambi" SessionField="CodModulo" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
<td>
<asp:Button ID="btnImprimir" runat="server" Text="Imprimir" EnableViewState="False"
Width="110px" ToolTip="Imprimir" Visible="False" />
</td>
</tr><tr>
<td>
<asp:Label id="Label6" runat="server">Ano:</asp:Label>
</td>
<td style="width: 650px;">
<asp:TextBox ID="Ano" runat="server" Style="text-align:center;" AutoPostBack="True" Width="40px" EnableViewState="False"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" OnClientHidden="onCalendarHidden" OnClientShown="onCalendarShown" BehaviorID="calendar1" Format="yyyy" Enabled="True" TargetControlID="Ano"></ajaxToolkit:CalendarExtender></td>
<td>
<asp:Button ID="btnFechar" runat="server" CausesValidation="false" Text="Fechar" ToolTip="Fechar" Width="110px" />
</td>
</tr></table>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:GridView ID="grvPrincipal" runat="server" PageSize="25"
DataSourceID="odsGrvPrincipal" EnableViewState="False" Width="850px" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Descricao" HeaderText="Descrição" SortExpression="Descricao" />
<asp:BoundField DataField="ordem" HeaderText="Und." SortExpression="ordem">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Jan" DataFormatString="{0:N0}" HeaderText="Jan" SortExpression="Jan" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Fev" DataFormatString="{0:N0}" HeaderText="Fev" SortExpression="Fev" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Mar" DataFormatString="{0:N0}" HeaderText="Mar" SortExpression="Mar" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Abr" DataFormatString="{0:N0}" HeaderText="Abr" SortExpression="Abr" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Mai" DataFormatString="{0:N0}" HeaderText="Mai" SortExpression="Mai" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Jun" DataFormatString="{0:N0}" HeaderText="Jun" SortExpression="Jun" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Jul" DataFormatString="{0:N0}" HeaderText="Jul" SortExpression="Jul" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Ago" DataFormatString="{0:N0}" HeaderText="Ago" SortExpression="Ago" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Set" DataFormatString="{0:N0}" HeaderText="Set" SortExpression="Set" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Out" DataFormatString="{0:N0}" HeaderText="Out" SortExpression="Out" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Nov" DataFormatString="{0:N0}" HeaderText="Nov" SortExpression="Nov" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Dez" DataFormatString="{0:N2}" HeaderText="Dez" SortExpression="Dez" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
<EmptyDataTemplate>
Nenhum registro foi encontrado!
</EmptyDataTemplate>
</asp:GridView>
</td>
<td>
</td>
</tr>
</table>
<asp:ObjectDataSource ID="odsGrvPrincipal" runat="server"
SelectMethod="IndicadoresSSMA" TypeName="Contrate.RES.DsAdmin.GeracaoResiduo"
EnableViewState="False" OldValuesParameterFormatString="original_{0}" InsertMethod="AlterarDadosAjusteResiduoGerado">
<InsertParameters>
<asp:Parameter Name="cod_geracao_grs" Type="Int32" />
<asp:Parameter Name="Parcela_Unidade" Type="Double" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="cod_nivel1_ni1" Name="cod_nivel1_ni1" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableViewState="False"
ShowMessageBox="True" ShowSummary="False" /></ContentTemplate>
</asp:UpdatePanel></asp:Content>