Results 1 to 4 of 4

Thread: How can the user control know which web form it is on. *RESOLVED*

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    How can the user control know which web form it is on. *RESOLVED*

    I have a user control on a webform. I need to put the user control on many web forms but the user control needs to know which web form it is on as different action will need to be taken depending on the web form.

    How can the user control know which web form it is on.
    Last edited by davidrobin; May 20th, 2004 at 06:18 AM.


    Things I do when I am bored: DotNetable

  2. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    EnsureChildControls()
    Me/this.Page.ID

    that should give you the name/id of the current page. you call EnsureChildControls to ensure Page will be there. Try not to think about the Me/this.Page.Page.Page.Page.Page.Page.Page.Page.Page.Page.ID issue it isn't documented if there is an issue.
    Magiaus

    If I helped give me some points.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    A little more information

    I need to set the text of a textbox control that is on a user control to the name of the containing page.

    The problem I am having is that the textbox is referenced as
    <current page> -> form1 -> header1 -> textbox1.

    Using ensurechildcontrols on my my page and placing
    VB Code:
    1. textbox1.text = me.page.id
    on the usercontrol when ran the textbox text is blank.

    I tried using a property on the Header1 control but when I type Header1.textbox1.text I get a 'header1' is not a member of 'test.Search'.


    Things I do when I am bored: DotNetable

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    I worked out how to do this using a property.

    This is on my usercontrol
    VB Code:
    1. Public WriteOnly Property pp() As String
    2.         Set(ByVal Value As String)
    3.             TextBox1.Text = Value
    4.         End Set
    5.     End Property

    This is in the general declaration section
    VB Code:
    1. Protected j As Header

    And finally this in the page load event
    VB Code:
    1. j = Me.FindControl("Header1")
    2.         j.pp = myTitle.InnerText

    I do have the me.ensurechildcontrols statement but it actually works without it.


    Things I do when I am bored: DotNetable

Posting Permissions

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



Click Here to Expand Forum to Full Width