find control from usercontrol i my masterpage?

Posted on 2011-10-04
Last Modified: 2012-05-12

I have:
Content page
Master page
usercontrol loaded on master page including liAmount

From content page, I want to change liAmount in my usercontrol at my masterpage.

How is this possible.

It would make sense if following would work;
((Literal)BasketAmount.Master.FindControl("liAmount")).Text = "1";
Question by:bongii
    LVL 17

    Accepted Solution

    Hello, in this way, follow this example:

    <%@ Control Language="C#" ClassName="MyUserControl" %>
    <script runat="server">
    <asp:Label Text="text" runat="server" ID="liAmount" />

    Open in new window

    <%@ Master Language="C#" %>
    <%@ Register Src="MyUserControl.ascx" TagName="MyUserControl" TagPrefix="uc1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <script runat="server">
    <html xmlns="">
    <head runat="server">
        <asp:ContentPlaceHolder ID="head" runat="server">
        <form id="form1" runat="server">
            <uc1:MyUserControl ID="MyUserControl1" runat="server" />
            <br />
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

    Open in new window

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %>
    <script runat="server">
        protected void Button1_Click(object sender, EventArgs e)
            UserControl myControl = (UserControl)this.Master.FindControl("MyUserControl1"); 
            ((Label)myControl.FindControl("liAmount")).Text = Environment.TickCount.ToString();
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Set Value" />

    Open in new window

    Or you can download the files from this link:

    Author Comment

    Ok i Will try that and get back to you. Thank you so far :))

    Author Comment

    Whank you, it works perfectly !!

    This was just what I was looking for:
    UserControl myControl = (UserControl)this.Master.FindControl("MyUserControl1");
    ((Label)myControl.FindControl("liAmount")).Text = Environment.TickCount.ToString();

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now