Click here to Skip to main content
15,846,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"
                <li class="menus">
                    <asp:LinkButton ID="lnkcategory" runat="server" OnCommand="LinkButton_Command" CommandArgument='<%# Eval("catid") %>'
                        Text='<%# Eval("catname") %>' CommandName="Show" ForeColor="White"></asp:LinkButton>

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 :)
Updated 4-Jan-12 12:33pm
Nicholas Butler 4-Jan-12 7:08am    
Repeater is a server-side control - it is not itself rendered in the HTML, just it's contents

Write following in click event of LinkButton
Share this answer
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
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900