开发者

UpdatePanel inside Repeater

In my UserControl, Im trying to update a updatepanel that is inside a repeater like this:

HTML-Markup

<asp:UpdatePanel ID="updDocumentQuickView" runat="server" UpdateMode="Conditional">
  <ContentTemplate>
    <asp:Repeater ID="repFolders" runat="server" OnItemDataBoun开发者_运维百科d="repFolders_OnItemDataBound" OnItemCommand="repFolders_OnItemCommand">
        <ItemTemplate>

            <asp:LinkButton ID="lnkFolder" runat="server"></asp:LinkButton>  

            <asp:UpdatePanel ID="updFiles" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Repeater ID="repFiles" runat="server" OnItemDataBound="repFiles_OnItemDataBound">
                        <ItemTemplate>
                            <%# Container.DataItem %> 
                        </ItemTemplate>                             
                    </asp:Repeater>   
                </ContentTemplate>                
            </asp:UpdatePanel>
        </ItemTemplate>        
    </asp:Repeater>
  </ContentTemplate>
</asp:UpdatePanel>

C#-code

protected void repFolders_OnItemCommand(object sender, CommandEventArgs e)
{  
    int intRow = -1;

    ScriptManager myScriptManager = (ScriptManager)Page.Master.FindControl("myScriptManager");

    Match myMatch = Regex.Match(myScriptManager.AsyncPostBackSourceElementID, "repFolders.ctl([0-9]*).lnkFolder");

    if (myMatch != null)        
        intRow = Convert.ToInt32(myMatch.Groups[1].Value);

    if (intRow > -1)
    {
        RepeaterItem myItem = repFolders.Items[intRow];

        Repeater repFiles = (Repeater)myItem.FindControl("repFiles");
        UpdatePanel updFiles = (UpdatePanel)myItem.FindControl("updFiles");

        string[] arr1 = new string[] { 
                                    "array item 1", 
                                    "array item 2", 
                                    "array item 3", 
                                    "array item 4", 
                                    "array item 5" };

        repFiles.DataSource = arr1;
        repFiles.DataBind();

        updFiles.Update();
    }
}

The end result I get is that updDocumentQuickView is the UpdatePanel that gets updated, and not updFiles. If i wrap an UpdatePanel around lnkFolder, then that UpdatePanel gets updated, with the same C# code. Ive checked what kind of data that are sent back with fiddler, and the wrong UpdatePanel is sent. Im getting the correct RepeaterItem, and both repFiles and updFiles are found. What do I miss to get the right UpdatePanel to get updated?

UPDATE

Hawxby solution solved the problem with updDocumentQuickView getting updated, thanks for that. But im still having problems with updFiles sending nothing back. Some further testing, with putting literals inside updFiles and working, tells me that theres something with repFiles that isnt returned. repFiles does have data that is bounded.

FINAL SOLUTION

repFiles.Visible were set to false in repFolders_OnItemDataBound, no wonder it didnt show.


It's likely because you have to explicitly set the async bindings

<asp:UpdatePanel ID="updDocumentQuickView" ChildrenAsTriggers="false">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="repFolders" EventName="repFolders_OnItemCommand" />
    </Triggers>

</asp:UpdatePanel>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜