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

ItemCommand event fires twice

5 Answers 454 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul J
Top achievements
Rank 1
Paul J asked on 01 Jul 2010, 01:34 PM
I know I must be doing something wrong here, but cannot figure out what it is.

Scenario:

I've got an ajaxified radGrid. It has a link button within one of the columns. I've added a conditionalpostback for this link button so when it fires it does a regular postback. but when the link button is pressed, the ItemCommand event gets fired twice for some reason. on clicking the linkbutton, i'm showing/hiding panels. Also, the grid exists within a user control, if that would make any difference.

any help is appreciated.


 <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"
    <script type="text/javascript"
 
 
           function conditionalPostback(sender, eventArgs) { 
               debugger; 
                if (eventArgs.get_eventTarget().indexOf("lbtnViewInfo") > -1) { 
                    eventArgs.set_enableAjax(false); 
                } 
 
            } 
               </script> 
    </telerik:RadScriptBlock> 
<telerik:RadAjaxManager ID="ramSearch" runat="server"
    <AjaxSettings>     
        <telerik:AjaxSetting AjaxControlID="rgGrid"
                <UpdatedControls>                     
                  <telerik:AjaxUpdatedControl ControlID="rgGrid" LoadingPanelID="RadAjaxLoadingPanel1" />                    
                </UpdatedControls>                                   
            </telerik:AjaxSetting>   
    </AjaxSettings> 
        <ClientEvents OnRequestStart="conditionalPostback" /> 
    </telerik:RadAjaxManager>  

 <telerik:RadGrid ID="rgGrid" runat="server" Width="100%" ShowStatusBar="False"  
           AutoGenerateColumns="False" PageSize="10" EnableViewState="true" AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True" Visible="true"
          
         
          <MasterTableView Width="100%" DataKeyNames="IDNumber"  AllowMultiColumnSorting="False">   
           <NoRecordsTemplate><div class="noRecords">Your search criteria did not return any results, or you did not first select any criteria to search on.</div> 
            </NoRecordsTemplate>       
         
                               
                <Columns> 
                    
                  <telerik:GridTemplateColumn UniqueName="FullName" SortExpression="FullName" HeaderText="Student Name" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Left"  HeaderStyle-HorizontalAlign="Center">   
                        <ItemTemplate>  
                        <asp:LinkButton ID="lbtnViewInfo" Font-Underline="true"  runat="server" CausesValidation="false" CommandName="ViewInfo" Width="100%" Text='<%#Eval("FullName") %>' />  
                        </ItemTemplate>  
                    </telerik:GridTemplateColumn>                                                                                                                                                         
                    </telerik:GridBoundColumn>                     
 
                </Columns> 
           </MasterTableView> 
       </telerik:RadGrid>    
Private Sub rgGrid_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgGrid.ItemCommand 
           
            Select Case e.CommandName 
                Case "ViewInfo" 
                 
                     panelInfo.Visible = True 
                     pnlsearch.Visible = False 
                     pnlGrid.Visible = False 
 
                Case Else 
                    Exit Sub 
            End Select 
        End Sub 

5 Answers, 1 is accepted

Sort by
0
Accepted
Radoslav
Telerik team
answered on 01 Jul 2010, 04:13 PM
Hello Paul,

I tried to reproduce the described issue, but to no avail. I am sending you a simple example based on your code. Please check it out and let me know what differs in your case.

Looking forward for your reply.

Best wishes,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Paul J
Top achievements
Rank 1
answered on 01 Jul 2010, 04:26 PM
Radoslav,

I figured out why it fires twice. Thanks for your help. I had left out some code, because I thought I had ruled it out already, but was wrong: for the link button i was also telling it to run a client side method upon click to explicitly show an ajaxloadingpanel:

 
        function ShowAjaxLoadingPanel() { 
            currentLoadingPanel = $find("<%= RadAjaxLoadingPanel1.ClientID%>"); 
            currentUpdatedControl = "<%= rgGrid.ClientID %>"
           currentLoadingPanel.show(currentUpdatedControl); 
        }   

 
      Private Sub rgGrid_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgStudents.ItemDataBound 
            If e.Item.ItemType = GridItemType.AlternatingItem Or e.Item.ItemType = GridItemType.Item Then 
                Dim item As GridDataItem 
                item = CType(e.Item, GridDataItem) 
                Dim lnkButton As LinkButton 
                lnkButton = CType(item("FullName").FindControl("lbtnViewStudentInfo"), LinkButton) 
 
                lnkButton.Attributes.Add("onclick""ShowAjaxLoadingPanel();" + Page.ClientScript.GetPostBackEventReference(lnkButton, "").ToString()) 
                 
            End If 
          
        End Sub 


it's the Page.ClientScript.GetPostBackEventReference(lnkButton, "").ToString() that was adding the second firing of the ItemCommand event. I bet when I found code to add the onclick event, the code sample I found had this in it, and I blindly decided to use it without even thinking about it. sigh. I need to pay more attention to things! Thanks for your help though!

Thanks!
0
Radoslav
Telerik team
answered on 02 Jul 2010, 09:38 AM
Hi Paul,

I am glad you solved the problem. In case you experience any further problems, do not hesitate to contact us again!

All the best,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ramesh
Top achievements
Rank 1
answered on 19 Apr 2012, 11:12 AM
Hi Radoslav,

In my case I have defined

 

OnItemCommand="rdGrdNonAssigned_OnItemCommand"

 

in aspx design itself. No where refering it to fire again. Still its is executing twice for me....

I am using rad loading panel...

<

 

telerik:RadAjaxLoadingPanel ID="SearchLoadingPanel" runat="server">

 

 

<img src='Images/loading.gif' alt="Loading..." style="border: 0;" />

 

</

 

telerik:RadAjaxLoadingPanel>

 


and using it in <telerik:AjaxSetting ... .. .
Please tell me what could be the issue...
0
Radoslav
Telerik team
answered on 24 Apr 2012, 07:49 AM
Hello Ramesh,

Based on the provided information is hard to say what is causing the described issue. Could you please post your aspx page with the related code behind file.  Thus we will be able to gather more details about your scenario and provide you with more to-the-point answer.  

Looking forward for your reply.

Kind regards,
Radoslav
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.
Tags
Grid
Asked by
Paul J
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Paul J
Top achievements
Rank 1
Ramesh
Top achievements
Rank 1
Share this question
or