在用户控件之外搜索控件

本文关键字:控件 搜索 用户 | 更新日期: 2023-09-27 18:05:33

我有buttonuser control AddPostUserControl。我想当user control AddPostUserControl火中的button的点击事件找到ID ShowPostsListViewasp:ListView。我该怎么做呢?

              <%--add post user control--%>
                <uc1:AddPostUserControl runat="server" id="AddPostUserControl" />
                <%--show posts--%>
                <asp:ListView ID="ShowPostsListView" runat="server">
                    <ItemTemplate>
                        <div class="thisPost">
                            <div class="thisPostAuthor">
                                <%# this.GetCurrentUser(Eval("User")) %>
                            </div>
                            <div class="thisPostHeader">
                                <h3>
                                    <%# Eval("Title") %>
                                </h3>
                                <span class="postDateTime">
                                    <%# Eval("PostDate") %>
                                </span>
                            </div>
                            <div class="thisPostContent">
                                <p>
                                    <%# Eval("PostContent") %>
                                </p>
                            </div>
                        </div>
                    </ItemTemplate>
                </asp:ListView>

在用户控件之外搜索控件

Page page = HttpContext.Current.Handler as Page
ListView lsv = page.FindControl("ShowPostsListView");