How do you refer to a textbox that is located in a User Control?

Discussion in 'ASP .Net' started by Mike Hnatt, Oct 22, 2003.

  1. Mike Hnatt

    Mike Hnatt Guest

    How can I refer to MyTextBox.Text which is located in mycontrol.ascx from
    within mymainpage.aspx? (i.e, mycontrol.ascx is a User Control located on
    mymainpage.aspx).

    Thanks!
    Mike
     
    Mike Hnatt, Oct 22, 2003
    #1
    1. Advertising

  2. Mike Hnatt

    Webdiyer Guest

    Make it a public property and you can refer to it from within container page
    by using this property.Hope it helps,thanks!

    "Mike Hnatt" <> дÈëÓʼþ
    news:...
    > How can I refer to MyTextBox.Text which is located in mycontrol.ascx from
    > within mymainpage.aspx? (i.e, mycontrol.ascx is a User Control located on
    > mymainpage.aspx).
    >
    > Thanks!
    > Mike
    >
    >
     
    Webdiyer, Oct 22, 2003
    #2
    1. Advertising

  3. Mike Hnatt

    Mike Hnatt Guest

    Can you give me a point in that direction?

    Thanks Webdiyer,
    But can anyone give me a hint as to what I need to do in order to do this?
    Mike

    "Webdiyer" <> wrote in message
    news:...
    > Make it a public property and you can refer to it from within container

    page
    > by using this property.Hope it helps,thanks!
    >
    > "Mike Hnatt" <> дÈëÓʼþ
    > news:...
    > > How can I refer to MyTextBox.Text which is located in mycontrol.ascx

    from
    > > within mymainpage.aspx? (i.e, mycontrol.ascx is a User Control located

    on
    > > mymainpage.aspx).
    > >
    > > Thanks!
    > > Mike
    > >
    > >

    >
    >
     
    Mike Hnatt, Oct 22, 2003
    #3
  4. Re: Can you give me a point in that direction?

    "Mike Hnatt" <> wrote in message
    news:...
    > Thanks Webdiyer,
    > But can anyone give me a hint as to what I need to do in order to do this?


    Mike, what part didn't you understand?
    --
    John

    > "Webdiyer" <> wrote in message
    > news:...
    > > Make it a public property and you can refer to it from within container

    > page
    > > by using this property.Hope it helps,thanks!
    > >
    > > "Mike Hnatt" <> дÈëÓʼþ
    > > news:...
    > > > How can I refer to MyTextBox.Text which is located in mycontrol.ascx

    > from
    > > > within mymainpage.aspx? (i.e, mycontrol.ascx is a User Control

    located
    > on
    > > > mymainpage.aspx).
    > > >
    > > > Thanks!
    > > > Mike
    > > >
    > > >

    > >
    > >

    >
    >
     
    John Saunders, Oct 22, 2003
    #4
  5. Mike Hnatt

    Mike Hnatt Guest

    Re: Can you give me a point in that direction?

    Thank John,

    Here is what I would "think" would work:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
    MyMainPageLabel.Text = "This is the first time viewing the page"
    Else
    MyMainPageLabel.Text = "The textbox value in the control is: " &
    Mycontrol1.MyControlTextBox.Text
    End If
    End Sub

    Based on a control called:
    <uc1:mycontrol id="Mycontrol1" runat="server"></uc1:mycontrol>

    Which in this user control, has a textbox:
    <asp:TextBox id="MyControlTextBox" runat="server">Somevalue</asp:TextBox>

    I have also tried refering to it as:
    mycontrol.MyControlTextBox.Text

    But I get a message saying it is inaccessible because it is "protected".

    Thanks for the help!

    Mike



    "John Saunders" <john.saunders at surfcontrol.com> wrote in message
    news:%...
    > "Mike Hnatt" <> wrote in message
    > news:...
    > > Thanks Webdiyer,
    > > But can anyone give me a hint as to what I need to do in order to do

    this?
    >
    > Mike, what part didn't you understand?
    > --
    > John
    >
    > > "Webdiyer" <> wrote in message
    > > news:...
    > > > Make it a public property and you can refer to it from within

    container
    > > page
    > > > by using this property.Hope it helps,thanks!
    > > >
    > > > "Mike Hnatt" <> дÈëÓʼþ
    > > > news:...
    > > > > How can I refer to MyTextBox.Text which is located in mycontrol.ascx

    > > from
    > > > > within mymainpage.aspx? (i.e, mycontrol.ascx is a User Control

    > located
    > > on
    > > > > mymainpage.aspx).
    > > > >
    > > > > Thanks!
    > > > > Mike
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Mike Hnatt, Oct 22, 2003
    #5
  6. Mike Hnatt

    Webdiyer Guest

    Re: Can you give me a point in that direction?

    Hi,Mike,add a public property to your user control like this:

    public string TextBoxText{
    get{return MyControlTextBox.Text;}
    set{MyControlTextBox.Text=value;}
    }

    then you can use MyMainPageLabel.Text=Mycontrol1.TextBoxText from within you
    container page.Note I'm using C#!


    "Mike Hnatt" <> дÈëÓʼþ
    news:...
    > Thank John,
    >
    > Here is what I would "think" would work:
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > If Not IsPostBack Then
    > MyMainPageLabel.Text = "This is the first time viewing the

    page"
    > Else
    > MyMainPageLabel.Text = "The textbox value in the control is: "

    &
    > Mycontrol1.MyControlTextBox.Text
    > End If
    > End Sub
    >
    > Based on a control called:
    > <uc1:mycontrol id="Mycontrol1" runat="server"></uc1:mycontrol>
    >
    > Which in this user control, has a textbox:
    > <asp:TextBox id="MyControlTextBox" runat="server">Somevalue</asp:TextBox>
    >
    > I have also tried refering to it as:
    > mycontrol.MyControlTextBox.Text
    >
    > But I get a message saying it is inaccessible because it is "protected".
    >
    > Thanks for the help!
    >
    > Mike
    >
     
    Webdiyer, Oct 23, 2003
    #6
  7. Mike Hnatt

    Mike Hnatt Guest

    Re: Can you give me a point in that direction?

    Perfect, thanks a lot. It worked! PS, I had to remember to add the line:
    Protected WithEvents Searchcontrol1 As myproject.mycontrol

    Mike

    "Webdiyer" <> wrote in message
    news:...
    > Hi,Mike,add a public property to your user control like this:
    >
    > public string TextBoxText{
    > get{return MyControlTextBox.Text;}
    > set{MyControlTextBox.Text=value;}
    > }
    >
    > then you can use MyMainPageLabel.Text=Mycontrol1.TextBoxText from within

    you
    > container page.Note I'm using C#!
    >
    >
    > "Mike Hnatt" <> дÈëÓʼþ
    > news:...
    > > Thank John,
    > >
    > > Here is what I would "think" would work:
    > >
    > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > > System.EventArgs) Handles MyBase.Load
    > > If Not IsPostBack Then
    > > MyMainPageLabel.Text = "This is the first time viewing the

    > page"
    > > Else
    > > MyMainPageLabel.Text = "The textbox value in the control is:

    "
    > &
    > > Mycontrol1.MyControlTextBox.Text
    > > End If
    > > End Sub
    > >
    > > Based on a control called:
    > > <uc1:mycontrol id="Mycontrol1" runat="server"></uc1:mycontrol>
    > >
    > > Which in this user control, has a textbox:
    > > <asp:TextBox id="MyControlTextBox"

    runat="server">Somevalue</asp:TextBox>
    > >
    > > I have also tried refering to it as:
    > > mycontrol.MyControlTextBox.Text
    > >
    > > But I get a message saying it is inaccessible because it is "protected".
    > >
    > > Thanks for the help!
    > >
    > > Mike
    > >

    >
    >
     
    Mike Hnatt, Oct 23, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Fallon

    User Control needs to refer to Page

    Joe Fallon, Feb 12, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    2,370
    Joe Fallon
    Feb 12, 2004
  2. Support
    Replies:
    3
    Views:
    4,361
    Support
    Jul 26, 2005
  3. John Salerno
    Replies:
    21
    Views:
    685
    Steve Holden
    May 18, 2006
  4. Jacob Donajkowski
    Replies:
    0
    Views:
    503
    Jacob Donajkowski
    Mar 7, 2007
  5. Jerry Qu
    Replies:
    1
    Views:
    523
    lee atkinson
    Feb 20, 2009
Loading...

Share This Page