find control from usercontrol i my masterpage?

Hi.

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:

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

Open in new window


MasterPage.master
<%@ Master Language="C#" %>

<%@ Register Src="MyUserControl.ascx" TagName="MyUserControl" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc1:MyUserControl ID="MyUserControl1" runat="server" />
        <br />
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

Open in new window


DemoUserControl.aspx
<%@ 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();
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Set Value" />
</asp:Content>

Open in new window


Or you can download the files from this link:
DemoUserControl.zip
0

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 :))
0
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();
0
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
C#

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.