find control from usercontrol i my masterpage?


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";
Jesper ChristensenProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carlos VillegasFull Stack .NET DeveloperCommented:
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:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jesper ChristensenProgrammerAuthor Commented:
Ok i Will try that and get back to you. Thank you so far :))
Jesper ChristensenProgrammerAuthor Commented:
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();
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.