Click here to Skip to main content
13,090,930 members (43,244 online)
Rate this:
Please Sign up or sign in to vote.
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 :)
Posted 4-Jan-12 0:43am
Updated 4-Jan-12 11:33am
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Write following in click event of LinkButton
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100