I'm working with asp:button e asp:Listbox
using the click
event of asp:button
to populate the listbox. I'm trying to manage so that no more postback occurs in the click
of the button event, but how I'm implementing is not working with updatePanel
, I'd like a collaboration to be able to heal and learn from the case. The code is as follows:
HTML:
<%@ Register Src="../Modelos/Cabecalho.ascx" TagName="Cabecalho" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Lysis</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script></head>
TreatmentwithUpdatePanel:
<asp:ScriptManagerID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updProcesso" UpdateMode="Conditional" runat="server" ChildrenAsTriggers="true">
<%--<asp:UpdatePanel ID="updProcesso" runat="server" >--%>
<ContentTemplate>
<table>
<tr>
<td>
Campos Disponíveis
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:ListBox ID="lstOrigem" CssClass="DropDownlist" runat="server" Height="200px"
Width="250px" SelectionMode="Multiple"></asp:ListBox>
</td>
<td>
<asp:Button ID="btnAcima" CssClass="Botao" runat="server" Text="Mover para Cima"
Width="110px" /><br />
<br />
<asp:Button ID="btnAbaixo" CssClass="Botao" runat="server" Text="Mover para Baixo"
Width="110px" /><br />
<br />
<asp:Button ID="btnSelecionar" CssClass="Botao" runat="server" Text="Selecionar"
Width="110px" /><br />
<br />
<asp:Button ID="btnDesfazer" CssClass="Botao" runat="server" Text="Desfazer Seleção"
Width="110px" />
</td>
</tr>
</table>
<table>
<tr>
<td>
Campos Selecionados
</td>
<td>
Ordem
</td>
<td>
</td>
<td>
Operação
</td>
</tr>
<tr>
<td>
<asp:ListBox ID="lstDestino" CssClass="DropDownlist" runat="server" Height="200px"
Width="250px" SelectionMode="Multiple"></asp:ListBox>
</td>
<td>
<asp:ListBox ID="lstOrdem" CssClass="DropDownlist" runat="server" Height="200px"
Width="50px"></asp:ListBox>
</td>
<td valign="top">
<asp:Button ID="btnMudaOrdem" CssClass="Botao" runat="server" Text="Mudar Ordem"
Width="95px" />
</td>
<td>
<asp:ListBox ID="lstOperacao" CssClass="DropDownlist" runat="server" Height="200px"
Width="115px"></asp:ListBox>
</td>
<td valign="top">
<asp:Button ID="btnMudaOperacao" CssClass="Botao" runat="server" Text="Mudar Operação"
Width="110px" />
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
Example of handling a Button:
Protected Sub btnSelecionar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSelecionar.Click
Try
ScriptManager1.RegisterPostBackControl(CType(sender, Control))
If lstOrigem.SelectedIndex <> -1 Then
If lstOrigem.SelectedIndex <> -1 Then
For item As Integer = lstOrigem.Items.Count - 1 To 0 Step -1
If lstOrigem.Items(item).Selected Then
Dim origem As New ListItem
origem.Text = "----"
origem.Value = lstOrigem.SelectedItem.Value
lstDestino.Items.Add(lstOrigem.SelectedItem)
lstOrdem.Items.Add(origem)
Dim operacao As New ListItem
operacao.Text = "----"
operacao.Value = lstOrigem.SelectedItem.Value
lstOperacao.Items.Add(operacao)
lstOrigem.Items.RemoveAt(lstOrigem.SelectedIndex)
lstDestino.ClearSelection()
End If
Next
End If
btnSelecionar.Focus()
updProcesso.Update()
End If
Catch ex As Exception
Session("erro") = ex
Response.Redirect("../Paginas/Erro.aspx")
End Try
End Sub