在UserControl之外搜索控件

时间:2013-03-22 13:59:05

标签: c# asp.net controls

我在button AddPostUserControl 中有user control。我希望当button AddPostUserControl 中的user control点击事件触发时,找到ID为 ShowPostsListView asp: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>

1 个答案:

答案 0 :(得分:1)

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