Access User Control Property from another code-beh

Results 1 to 2 of 2

Thread: Access User Control Property from another code-beh

  1. #1
    Join Date
    Dec 1969

    Default Access User Control Property from another code-beh

    All, right i have a ascx file with a corresponding public property, inside the code behind is the following<BR>===================================== =================<BR>Public MustInherit Class header1<BR> Inherits System.Web.UI.UserControl<BR><BR> Protected WithEvents title As System.Web.UI.HtmlControls.HtmlGenericControl<BR>< BR> Public Property pageTitle() As String<BR> Get<BR> Return title.InnerText<BR> End Get<BR> Set(ByVal Value As String)<BR> If Value = "" Then<BR> title.InnerText = "Welcome to My Site"<BR> Else<BR> title.InnerText = Value<BR> End If<BR> End Set<BR> End Property<BR><BR> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> End Sub<BR>End Class<BR>========================================= =============<BR><BR>I have a number of pages that include that header.ascx file, i am having a difficult time setting that poperty from the code-behind of this page<BR><BR>So in the aspx page itself, i have:<BR>&#060;%@ Register TagPrefix="uc1" TagName="header1" Src="/common/template/header1.ascx" %&#062;<BR><BR>and later<BR>&#060;uc1:header1 id="Header1" runat="server" /&#062;<BR><BR>mainly i have no idea to reference the UserControl "Header1" from the code behind to dynamically set that title<BR><BR>thanks in advance

  2. #2
    Join Date
    Dec 1969

    Default RE: Access User Control Property from another code

    from the codebehind that wished to set the properties of that control, try:<BR><BR>UserControl uc = (UserControl)this.Parent.Page.FindControl("Name_of _HeaderControl_as_listed_in_ID_property");<BR><BR> uc.PropertyYouWishToChange = value;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts