This is a migrated thread and some comments may be shown as answers.

SelectedIndexChanged firing involuntarily after a postback

6 Answers 231 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leandro
Top achievements
Rank 1
Leandro asked on 20 Jul 2012, 08:46 PM
Good afternoon,

I have the following problem in my RadGrid have a column with the command button "select" to fire the SelectedIndexChanged event.
So far so good, when you click the button, it triggers the normal SelectedIndexChanged event.
The problem occurs when I select a row, without clicking on the button by clicking on the same line, and soon after I click for example on one other button, by doing this, it seems that for the button to cause a postback on the page, it triggers the SelectedIndexChanged event of RadGrid.

   <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">
            function Lancar_Tarefa(id) {               
                window.radopen("Agenda_Tarefa_Novo.aspx?Id=" + id, "AgendaTarefa");
            }
             
            function Msg(msg, tipo) {
                window.radopen("Msg.aspx?Texto=" + msg + "&Tipo=" + tipo, "Msg");
                return false;
            }
 
        </script>
    </telerik:RadScriptBlock>
 
   <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="btnFiltrar">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="PanelAgenda" LoadingPanelID="RadAjaxLoadingPanel1" />
                    <telerik:AjaxUpdatedControl ControlID="pnGrid" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Skin="Windows7" runat="server"></telerik:RadAjaxLoadingPanel>

       <
telerik:RadButton ID="btnFiltrar" runat="server" Skin="Web20" Text="Filtrar"
       Width="90px" style="margin-right:10px;">
<Icon PrimaryIconUrl="../../Icones/VizualizarGrid2.png" />
</telerik:RadButton>
 
<asp:Panel ID="pnGrid" runat="server">
<telerik:RadGrid ID="gridAgenda" runat="server" Width="710px" Height="462px"
                        Skin="Outlook" AutoGenerateColumns="False" CellSpacing="0"
                        GridLines="None">
                        <ClientSettings>
                            <Selecting AllowRowSelect="True" />
                            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                        </ClientSettings>
                        <MasterTableView>
                            <CommandItemSettings ExportToPdfText="Export to PDF" />
                            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"
                                Visible="True">
                                <HeaderStyle Width="20px" />
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"
                                Visible="True">
                                <HeaderStyle Width="20px" />
                            </ExpandCollapseColumn>
                            <Columns>
                                <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Select"
                                    FilterControlAltText="Filter column column" ImageUrl="~/Icones/Grid.gif"
                                    UniqueName="column">
                                    <HeaderStyle Width="35px" />
                                    <ItemStyle HorizontalAlign="Center" Width="35px" />
                                </telerik:GridButtonColumn>
                                <telerik:GridDateTimeColumn DataField="DFdata_inicio"
                                    FilterControlAltText="Filter DFdata_inicio column" HeaderText="Data/Hora"
                                    UniqueName="DFdata_inicio">
                                    <HeaderStyle Width="120px" />
                                    <ItemStyle Width="120px" />
                                </telerik:GridDateTimeColumn>
                                <telerik:GridBoundColumn DataField="DFid_agenda_relacionada"
                                    FilterControlAltText="Filter DFid_agenda_relacionada column" HeaderText="ID"
                                    UniqueName="DFid_agenda_relacionada">
                                    <HeaderStyle Width="50px" />
                                    <ItemStyle Width="50px" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="DFfase"
                                    FilterControlAltText="Filter DFfase column" HeaderText="Fase"
                                    UniqueName="DFfase" Visible="false">
                                    <HeaderStyle Width="40px" />
                                    <ItemStyle Width="40px" />
                                </telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn HeaderText="Fase" UniqueName="Fase">
                                    <ItemTemplate>
                                        <asp:Panel ID="CorFase" runat="server" Height="20px" Width="20px" />
                                    </ItemTemplate>
                                    <HeaderStyle Width="40px" />
                                    <ItemStyle HorizontalAlign="Center" Width="40px" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn DataField="DFusuario_agenda"
                                    FilterControlAltText="Filter DFusuario_agenda column" HeaderText="Agenda"
                                    UniqueName="DFusuario_agenda">
                                    <HeaderStyle Width="85px" />
                                    <ItemStyle Width="85px" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="DFtarefa"
                                    FilterControlAltText="Filter DFtarefa column" HeaderText="Tarefa"
                                    UniqueName="DFtarefa">
                                    <HeaderStyle Width="200px" />
                                    <ItemStyle Width="200px" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="DFenviado_por"
                                    FilterControlAltText="Filter DFenviado_por column" HeaderText="Enviado Por"
                                    UniqueName="DFenviado_por">
                                    <HeaderStyle Width="85px" />
                                    <ItemStyle Width="85px" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="DFcliente"
                                    FilterControlAltText="Filter DFcliente column" HeaderText="Cliente"
                                    UniqueName="DFcliente">
                                    <HeaderStyle Width="200px" />
                                    <ItemStyle Width="200px" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="DFid_agenda"
                                    FilterControlAltText="Filter DFid_agenda column" HeaderText="DFid_agenda"
                                    UniqueName="DFid_agenda" Visible="False">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="DFid_usuario_agenda"
                                    FilterControlAltText="Filter DFid_usuario_agenda column"
                                    HeaderText="DFid_usuario_agenda" UniqueName="DFid_usuario_agenda"
                                    Visible="False">
                                </telerik:GridBoundColumn>
                            </Columns>
                            <EditFormSettings>
                                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                </EditColumn>
                            </EditFormSettings>
                        </MasterTableView>
                        <FilterMenu EnableImageSprites="False">
                        </FilterMenu>
                    </telerik:RadGrid>
</asp:Panel>


   Private Sub gridAgenda_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles gridAgenda.SelectedIndexChanged
        If gridAgenda.SelectedItems.Count > 0 Then
            For Each Row As GridDataItem In gridAgenda.SelectedItems
                If cmbUsuario.SelectedValue = "" Then
                    clsVariavel_Sessao.Agenda_IdUsuario = Row("DFid_usuario_agenda").Text
                    TableRetorno = clsConexao.Executar_Retornar("SELECT lcase(DFnome), lcase(DFemail) FROM TBusuario WHERE DFid_usuario = " & Row("DFid_usuario_agenda").Text)
                    clsVariavel_Sessao.Agenda_Usuario = TableRetorno(0)(0)
                    clsVariavel_Sessao.Agenda_UsuarioLogin = TableRetorno(0)(1)
                End If
                ScriptManager.RegisterClientScriptBlock(Me, [GetType](), "Tarefa", "Lancar_Tarefa(" & Row("DFid_agenda").Text & ")", True)
            Next
        End If
 
        Exit Sub
Erro:
        MensagemBox("Operação cancelada.", TipoMsg.Erro, Page)
        Call Gravar_Log_Erro(Err.Description, clsVariavel_Sessao.Erro, clsVariavel_Sessao.Default_UsuarioLogadoID, clsVariavel_Sessao.Default_UsuarioLogadoLogin, clsVariavel_Sessao.Default_UsuarioLogadoIP, clsVariavel_Sessao.SiteMaster_FormularioID, clsVariavel_Sessao.SiteMaster_urlWithSessionID, "gridAgenda_SelectedIndexChanged")
    End Sub

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Jul 2012, 08:08 AM
Hi Leandro,

I guess your requirement is to prevent entering the SelectedIndexChange Event on an external button click event after selecting a row.

ASPX:
<asp:Button ID="Button1" runat="server" Text="Button1" 
        CommandName="save" UseSubmitBehavior="false" onclick="Button1_Click" />

VB:
Protected Sub gridAgenda_SelectedIndexChanged(sender As Object, e As EventArgs)
             
    If Request.Form("__EVENTTARGET").ToString() <> "Button1" Then
          'your code
    End If
End Sub

Thanks,
Shinu.
0
Leandro
Top achievements
Rank 1
answered on 23 Jul 2012, 11:49 AM
Hi Shinu,

the "Request.Form (" __EVENTTARGET "). ToString ()" is returning me nothing, what should I do?
0
Leandro
Top achievements
Rank 1
answered on 23 Jul 2012, 11:54 AM
Sorry sorry, my mistake, I wrote the name of the event wrong: S
How would I do in the case to put the "UseSubmitBehavior" in GridColumnButton?
Why does the form contain various buttons and other components that cause postback, if I treat each control will be feasible.
I would check the "SelectedIndexChanged" routine to run only if called by the click of the button column.

Thank you.
0
Leandro
Top achievements
Rank 1
answered on 24 Jul 2012, 12:14 PM
And there? any solution?
0
Marin
Telerik team
answered on 25 Jul 2012, 09:17 AM
Hello,

 This happens because you have enabled the client-side selection of the grid which selects a row whenever you click inside it. To prevent this behavior you should set AllowRowSelect="false". This way a row will be selected only by clicking on the button column which fires the select command.

Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Leandro
Top achievements
Rank 1
answered on 25 Jul 2012, 11:53 AM
Beauty! This solves for me on screen that I use the button "selected" with the event "SelectedIndexChanged". Thank you Marin.
Tags
Grid
Asked by
Leandro
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Leandro
Top achievements
Rank 1
Marin
Telerik team
Share this question
or