Referencing User Control Attributes in Page Code Behind

.net , user control , code behind United States
  • 5 years ago

    I'm trying to reference the attributes of a panel in a User Control in the code behind of a web page. I've tried about a dozen variations. Can't be this hard. Anybody got the correct syntax? Thanks!

    <%@ Register Src="~/inc/ceSteps.ascx" TagName="ceSteps" TagPrefix="uc1" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <uc1:ceSteps ID="ceSteps" runat="server" />
    
    Then on the code behind for my page:
    Dim myCtrl As UserControl = CType(FindControl("uc1"), UserControl)
    myCtrl.pnlStage1.BackColor = System.Drawing.ColorTranslator.FromHtml("#dfdfdf")
    
    yahda, yahda, yahda....
    

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An expert is a man who has made all the mistakes that can be made in a very narrow field” - Niels Bohr