从其他页面查找母版转发器内的链接按钮 [英] Find Linkbutton inside repeater of master page from other pages

查看:69
本文介绍了从其他页面查找母版转发器内的链接按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在另一个页面的母版页中禁用侧数据转发器中的链接按钮。我正在尝试在母版页中创建页面列表,当单击其中一个链接时,它会将用户重定向到该页面。因此,当页面中的用户,其相应的链接应该被禁用,这是在母版页中。以下是我的代码:



母版页:



I am trying to disable a linkbutton in side data repeater in masterpage from another page. I am trying to create list of pages in masterpage, when one of the link is clicked, it redirects user to that page. So, when the user in the page, its respective link should be disabled, which is in master page. Here are my codes:

Master page:

<asp:ContentPlaceHolder ID="CategoryMenuHolder" runat="server">
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"

        onitemcommand="Repeater1_ItemCommand">
        <ItemTemplate>
            <ul

                <li class="menus">
                    <asp:LinkButton ID="lnkcategory" runat="server" OnCommand="LinkButton_Command" CommandArgument='<%# Eval("catid") %>'

                        Text='<%# Eval("catname") %>' CommandName="Show" ForeColor="White"></asp:LinkButton>
            
                </li>
            </ul>
        </ItemTemplate>
    </asp:Repeater>
</asp:ContentPlaceHolder>



内容页


content page

ContentPlaceHolder holder = (ContentPlaceHolder)Master.FindControl("CategoryMenuHolder");
        Repeater rep = (Repeater)holder.FindControl("Repeater1");



但是转发器是空的!

我该怎么做?

提前谢谢:)


but the repeater comes in as null!
How do I do this?
Thanks in advance :)

推荐答案

中写下以下事件 LinkBut​​ton

Write following in click event of LinkButton
LinkButton.Enabled=false;


首先将转发器驻留在母版页中,以获得转发器控制的参考使用以下代码

first fine the repeater resides in the master page, to get the reference of repeater control use following code
Repeater rpt = (Repeater)Master.FindControl("Repeater1");




to get the object of LinkButton that resides in Repeater item use bellow code




foreach (ListViewItem li in rpt.Items)
        {
           //Finds LinkButton button from Repeater
            LinkButton lkb=(LinkButton) li.FindControl("lnkcategory");
           //Disable LinkButton
            lkb.Enabled = false;
        }




I above code will be helpful to you, if this solution comes helpful to you please give rank to me
Thanks


这篇关于从其他页面查找母版转发器内的链接按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆