Problems with Repeater ItemCommand Event and UpdatePanel Triggers

Last post 12-19-2008 9:54 AM by aspwhiz. 16 replies.

Sort Posts:

  • Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    09-26-2006, 1:50 PM
    • Member
      30 point Member
    • eCoGoblin
    • Member since 02-24-2005, 12:39 PM
    • Posts 7

    Hello,
    I have an UpdatePanel with a big photo, and outside of the UpdatePanel i have a Repeater that shows some thumbnails.
    The code is something like this:
     

    <cc1:UpdatePanel ID="PanelFotoGrande" runat="server" Mode="Conditional">
    <ContentTemplate>
        <asp:Image ID="imgFotoGrande" runat="server" />
    </ContentTemplate>
    <Triggers>
        <cc1:ControlEventTrigger ControlID="Button1" EventName="Click" />
    </Triggers>
    </cc1:UpdatePanel>
    
    <asp:Repeater ID="rptMiniaturas"...>
        <ImageButton... /> (...Thumbnails...)
    </asp:Repeater>

     
     But it doesn't work. I'm sure that the problem is something about the Repeater control. If I try the same, but in place of a Repeater ItemCommand Event I use a Button Click Event, all works correctly.
    I mean something like this:

     

    <cc1:UpdatePanel ID="PanelFotoGrande" runat="server" Mode="Conditional">
    <ContentTemplate>
    
        <asp:Image ID="imgFotoGrande" runat="server" />
    
    </ContentTemplate>
    <Triggers>
        <cc1:ControlEventTrigger ControlID="Button1" EventName="Click" />
    </Triggers>
    </cc1:UpdatePanel>
    
    <asp:Button ID="btnFoto" runat="server" Text="btnFoto" />

     Can somebosy help me with that issue?
    Thanks!
     

     

  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    09-26-2006, 5:59 PM
    • Contributor
      7,416 point Contributor
    • Garbin
    • Member since 09-17-2004, 12:35 PM
    • Sassari, Italy
    • Posts 1,506
    • ASPInsiders
      TrustedFriends-MVPs

    Hi,

    I think you've hit a bug with UpdatePanel and the ItemCommand event when Mode="Conditional".

    It is mentioned also in this article by Rick Strahl

    Alessandro Gallo | Blog | My book: ASP.NET AJAX In Action
  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    09-26-2006, 6:33 PM
    • Member
      30 point Member
    • eCoGoblin
    • Member since 02-24-2005, 12:39 PM
    • Posts 7

    Thanks Garbin,

    I read it. I have no idea how to make the behavior i want. I would like to refresh the big image, and some other things around de image, like nº of votes... I think in atlas for that purpose, because I would like to keep the thumbnails scroll in the same position when refreshing the image.

    Have any idea about to make that behavior? Sorry about my english ;-)

    Thanks.

  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    02-15-2007, 6:05 PM
    • Member
      8 point Member
    • MrPredator
    • Member since 02-01-2007, 7:45 PM
    • Posts 4
    I was looking at this post and your code and I see that you set your trigger to respond to a button's Click event inside the repeater.  The Triger will not find the button that way.  You may want to try to set the control to be the Repeater itself and the event the itemCommand.  i have not tried this but you may want to give it a shot.
  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    12-27-2007, 12:29 PM
    • Member
      30 point Member
    • eCoGoblin
    • Member since 02-24-2005, 12:39 PM
    • Posts 7

    Yes MrPredator, You are right. I have some mistakes in the code, but just mistakes when writting here. So, this is the real code:

    <cc1:UpdatePanel ID="PanelFotoGrande" runat="server" Mode="Conditional">
    <ContentTemplate>
        <asp:Image ID="imgFotoGrande" runat="server" />
    </ContentTemplate>
    <Triggers>
        <cc1:ControlEventTrigger ControlID="rptMiniaturas" EventName="ItemCommand" />
    </Triggers>
    </cc1:UpdatePanel>
    
    <asp:Repeater ID="rptMiniaturas"...>
        <ImageButton... /> (...Thumbnails...)
    </asp:Repeater>
    But this is the issue. It doesnt works correctly.
    Maybe with the new AJAX Toolkit it works fine? Somebody knows?
    Thanks to all.
  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    12-27-2007, 10:29 PM
  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    04-03-2008, 5:07 PM
    • Member
      24 point Member
    • dtabraha
    • Member since 01-26-2006, 6:19 PM
    • Posts 7

    The problem is probably with rebinding your repeater on the postbacks.

     http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskrespondingtobuttoneventsindatalistitems.asp

    Scott Mitchell has a very good post on this:

    http://forums.asp.net/p/580720/1909340.aspx

  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    09-05-2008, 1:51 PM

    Hi,

    I have read and re-read the all the posts and links given in this thread but I am unable to get my code fixed which is to do with update panels and repeaters. So I thought I might as well put my question to all of you folks. I really need an answer. So any help is welcome.

    I have a data bound repeater which is inside an update panel and within that repeater there is another update panel containing a link button marked "Delete". This means there is a Delete link button in each row of the repeater. What I want is to be able to delete the row by clicking on the link button. On clicking the delete button the user is asked to confirm the delete and then the record in the database corresponding to the row is deleted and then the repeater is bound again.

    My code is given below

    abc.ascx

    <%@ Control Language="c#" AutoEventWireup="True" Codebehind="abc.ascx.cs" Inherits="abc" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
                            <asp:UpdatePanel ChildrenAsTriggers="true" ID="UpdatePanel1" runat="server">
                            <ContentTemplate>                                                                       
                            <asp:Repeater id="rprTasks" runat="server" OnItemCommand="rprTasks_ItemCommand">
                            <ItemTemplate>

                             <tr>
                                <td>
                                     [<%# DataBinder.Eval(Container, "DataItem.Task_Number") %>
     </td>

    </tr> 

    <tr>
                                <td>
                                  <asp:UpdatePanel UpdateMode="Conditional" ID="UpdatePanel2" runat="server">
                                  <ContentTemplate>                                

                                  <asp:LinkButton OnClientClick="return confirmDelete();" CommandName="Remove" CommandArgument=" [<%#DattaBinder.Eval(Container, "DataItem.Task_Number")%> ID ="HyperDel" runat="server" Text="Delete" />

                                              </ContentTemplate>
                                  <triggers>
                                   <asp:AsyncPostBackTrigger ControlID="HyperDel" EventName="Click" />
                                  </triggers>                                                   
                                  </asp:UpdatePanel>

                                 </td>
                            </tr>
                        </itemtemplate>                   
                        </asp:Repeater>
                            </ContentTemplate>
                            </asp:UpdatePanel>
                         <script type="text/javascript">
                         function confirmDelete()
                         {
                          var answer = confirm("Delete this ticket?")
                          if (answer)
                          {
                            return true;            
                          }
                          else
                          {
                           return false;
                          }                    
                         }
                         </script>                   

    The code which does the deletion in the database  is given below. I am using the ItemCommand event of the repeater to delete the record in the database

    abc.aspx.cs 

    protected void rprTasks_ItemCommand(object source, RepeaterCommandEventArgs e)
     {
        if (e.CommandName == "Remove")
        {
          Guid pri = new Guid(e.CommandArgument.ToString());
          DeletefTask(pri);               
        }
    }

    Finally I re-bind the repeater in the Click event of the link button as given below.

    private void HyperDel_Click(object sender, EventArgs e)
    {
       this.BindRepeater();
    }

    When I click on the delete link button I get the confirmation message and after confirmation the record also gets deleted but the row does not disappear from the repeater. It just sits there. If I again reload the page I find the row does not appear again. I want the corresponding row in the repeater to disappear. I have to do this through ajax and partial refresh only. Any help is very welcome.

    Thanks,
    Jai
     

  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    09-10-2008, 5:52 AM
    • Member
      2 point Member
    • drodecker
    • Member since 05-24-2007, 8:21 PM
    • Posts 1

     I had the same issue.  This is a seemingly simple Ajax control, but alas, Microsoft has some idiosyncricities to work around.

    In the ItemCommand, when you perform the Delete, you'll need to do another DataBind with the Repeater control.

    Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

     

    Best regards,

    David Rodecker

    Founder & CTO, RelevantAds

    “getting local business online"


     
  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    10-14-2008, 5:20 AM
    • Member
      2 point Member
    • Kung Nicke
    • Member since 10-14-2008, 9:17 AM
    • Posts 1

    I had the same issue with linkbuttons in a repeater wanting to update another updatepanel. I solved this by making sure that my linkbuttons had the attribut ID=... set to a value..




  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    12-15-2008, 10:41 AM
    • Member
      4 point Member
    • sgon1853
    • Member since 12-10-2007, 4:46 PM
    • Posts 2

     

    Hola lo que debes hacer es en el codigo del itemdatabound del repeater el siguiente codigo por ej.

    protected void RepeatEntidades_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e.Item.ItemType != ListItemType.Item) return;

    CheckBox chk = (CheckBox)e.Item.FindControl("CheckBox1");
    if (chk == null) return;

    ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(chk);
    }


    ahi lo que haces es que cada vez que enlazas un item al repeater lo matriculas como control para realizar un postback asincronico. a mi me funciona perfecto, Saludos.
     
    y el html 
     
    <asp:Repeater ID="RepeatEntidades" runat="server"
                            DataMember="INFORMATION_SCHEMA.TABLES"
                            onitemdatabound="RepeatEntidades_ItemDataBound">
                        <HeaderTemplate>
                            <tr>
                                <td class="tituloTabla">
                                     <asp:Label ID="Label2" runat="server" Text="Entidades:"></asp:Label>  
                                </td>
                            </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                    <asp:CheckBox AutoPostBack="true" ID="CheckBox1" Text='<%# Eval("tabla") %>'
                                        runat="server" oncheckedchanged="CheckBox1_CheckedChanged" />
                                </td>
                            </tr>
                        </ItemTemplate>
                        </asp:Repeater>
     
    <asp:UpdatePanel ID="UpdatePanelAtributos" runat="server" UpdateMode="Conditional"
                     RenderMode="Inline" onload="UpdatePanelAtributos_Load">
                    </asp:UpdatePanel>

  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    12-18-2008, 2:53 AM

    Hello !!! Your solution looks promising. But unfortunately I am unable to understand the language in which you have replied. And I live in India where it is very difficult to find someone who knows Spanish or French (I am not sure which language you have used). The problem I am having is still pending. So I would be very obliged to you if you could post the solution in English once again sothat I understand it and can try it out. Thanks and regards, Jayakumar

  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    12-18-2008, 7:57 AM
    • Member
      4 point Member
    • sgon1853
    • Member since 12-10-2007, 4:46 PM
    • Posts 2
    Hello man, no problem
    you must to catch the item databound event and in it write the following code, Eg.


    protected void RepeatEntidades_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem)
        {

            CheckBox chk = (CheckBox)e.Item.FindControl("CheckBox1");
            if (chk == null) return;

            ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(chk);
        }
    }

     
    the code above obtain the items in the repeater and register that like asyncpostback, for me works perfect. and the asp code:
    y el html 
     
    <asp:Repeater ID="RepeatEntidades" runat="server"
                            DataMember="INFORMATION_SCHEMA.TABLES"
                            onitemdatabound="RepeatEntidades_ItemDataBound">
                        <HeaderTemplate>
                            <tr>
                                <td class="tituloTabla">
                                     <asp:Label ID="Label2" runat="server" Text="Entidades:"></asp:Label>  
                                </td>
                            </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                    <asp:CheckBox AutoPostBack="true" ID="CheckBox1" Text='<%# Eval("tabla") %>'
                                        runat="server" oncheckedchanged="CheckBox1_CheckedChanged" />
                                </td>
                            </tr>
                        </ItemTemplate>
                        </asp:Repeater>
     
    <asp:UpdatePanel ID="UpdatePanelAtributos" runat="server" UpdateMode="Conditional"
                     RenderMode="Inline" onload="UpdatePanelAtributos_Load">
                    </asp:UpdatePanel>

     any suggestion dont dude to write me

  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    12-19-2008, 4:46 AM

    Hi,

    What you have done is to change the text for the check box based on a database table. But my question is very different. I will use your code itself to demonstrate what I want. Instead of the just substitute it with text from a record in the table.

     

     <asp:UpdatePanel ID="UpdatePanelAtributos" runat="server" UpdateMode="Conditional"
                     RenderMode="Inline" onload="UpdatePanelAtributos_Load"
    >

    <asp:Repeater ID="RepeatEntidades" runat="server"

                           DataMember="INFORMATION_SCHEMA.TABLES"

                            onitemdatabound="RepeatEntidades_ItemDataBound">
                        <HeaderTemplate>
                            <tr>
                                <td class="tituloTabla">
                                     <asp:Label ID="Label2" runat="server" Text="Entidades:"></asp:Label>  
                                </td>
                            </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                    
    [<%# DataBinder.Eval(Container, "DataItem.Task_Number") %>
                                </td>
                                <td>
    <asp:LinkButton CommandName="Remove" CommandArgument=" [<%#DattaBinder.Eval(Container, "DataItem.Task_Number")%> ID ="HyperDel" runat="server" Text="Delete" />                               
                                </td>
                        </tr>
                        </ItemTemplate>
                        </asp:Repeater>
    </asp:UpdatePanel>
     
     
    And the code
    protected void RepeatEntidades_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

    if (e.CommandName == "Remove")
        {
          Guid pri = new Guid(e.CommandArgument.ToString());
          DeletefTask(pri);   
    /* Function to delete record containing the task_number which is currently displayed in the repeater. On deleting this record here the data displayed in the repeater should actually dispappear. That does not happen and it simply sits there even though in the database the record gets deleted. */
        }
    }
     
    I hope that explains my problem. If you can find an answer to that I would be very happy to know of it.
     
    Warm Regards,
    Jayakumar
  • Re: Problems with Repeater ItemCommand Event and UpdatePanel Triggers

    12-19-2008, 4:50 AM

    Hi,

    What you have done is to change the text for the check box based on a database table. But my question is very different. I will use your code itself to demonstrate what I want. Instead of the just substitute it with text from a record in the table.

     

     <asp:UpdatePanel ID="UpdatePanelAtributos" runat="server" UpdateMode="Conditional"
                     RenderMode="Inline" onload="UpdatePanelAtributos_Load"
    >

    <asp:Repeater ID="RepeatEntidades" runat="server"

                           DataMember="INFORMATION_SCHEMA.TABLES"

                            onitemdatabound="RepeatEntidades_ItemDataBound">
                        <HeaderTemplate>
                            <tr>
                                <td class="tituloTabla">
                                     <asp:Label ID="Label2" runat="server" Text="Entidades:"></asp:Label>  
                                </td>
                            </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                    
    [<%# DataBinder.Eval(Container, "DataItem.Task_Number") %>
                                </td>
                                <td>
    <asp:LinkButton CommandName="Remove" CommandArgument=" [<%#DattaBinder.Eval(Container, "DataItem.Task_Number")%> ID ="HyperDel" runat="server" Text="Delete" />                               
                                </td>
                        </tr>
                        </ItemTemplate>
                        </asp:Repeater>
    </asp:UpdatePanel>
     
     
    And the code
    protected void RepeatEntidades_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    if (e.CommandName == "Remove")
        {
          DeletefTask(
    e.CommandArgument.ToString());    /* Function to delete record containing the task_number which is currently displayed in the repeater. On deleting this record in the table in the database the data displayed in the repeater should actually dispappear. That does not happen and it simply sits there even though in the database the record gets deleted. */
        }
      }
    }
     
    I hope that explains my problem. If you can find an answer to that I would be very happy to know of it.
     
    Warm Regards,
    Jayakumar
Page 1 of 2 (17 items) 1 2 Next >