Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How do you refer to a textbox that is located in a User Control?

Reply
Thread Tools

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

 
 
Mike Hnatt
Guest
Posts: n/a
 
      10-22-2003
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


 
Reply With Quote
 
 
 
 
Webdiyer
Guest
Posts: n/a
 
      10-22-2003
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
>
>



 
Reply With Quote
 
 
 
 
Mike Hnatt
Guest
Posts: n/a
 
      10-22-2003
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
> >
> >

>
>



 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      10-22-2003
"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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Mike Hnatt
Guest
Posts: n/a
 
      10-22-2003
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
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Webdiyer
Guest
Posts: n/a
 
      10-23-2003
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
>



 
Reply With Quote
 
Mike Hnatt
Guest
Posts: n/a
 
      10-23-2003
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
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Loading Data in to a Textbox located in MultiView that is in a Login View Jacob Donajkowski ASP .Net 0 03-07-2007 10:08 PM
where do you run database scripts/where are DBs 'located'? John Salerno Python 21 05-18-2006 05:39 AM
how to refer to a registered assembly located in GAC Support ASP .Net 3 07-26-2005 03:40 PM
Cannot log you on since your profile cannot be located psion Computer Support 0 12-31-2004 02:32 AM
How to refer to textbox in class? John Mason ASP .Net 3 11-23-2004 11:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57