Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Masterpage
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 Smile | :)
Posted 4-Jan-12 1:43am
Edited 4-Jan-12 12:33pm
v3
Comments
Nicholas Butler at 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
good
Please Sign up or sign in to vote.

Solution 1

Write following in click event of LinkButton
LinkButton.Enabled=false;
  Permalink  
v2
Rate this: bad
good
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
Thanks
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
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