Retreiving a value from Web User Control

I

Igor

Hi

How can I reference a specific control in a web user form from web form's
(page) code behind. In other words: I have a page (a web form) that has a
web user form in it. I want to read a value in code behind of that page (web
form) from a text box in the web user form.

Kind regards
 
M

Munna

Hi

if html is

<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>

in code behind

protected void Page_Load(object sender, EventArgs e)
{
string House = TextBox1.Text;
}

Thanks

Munna
 
I

Igor

Sorry, my mistake

How can I reference a specific control in a web user form from web form's
(page) code behind. In other words: I have a page (a web form) that has a
web user form in it. I want to read a value in code behind of that page (web
form) from a text box in the web user CONTROL - not form.

So I have <form id="form1" runat="server"> and that form has a "nested" web
user control by <%@ Register Src="Controls/NewWebUserControl1.ascx"
TagName="WebUserControl1" TagPrefix="uc1" %>. That WEB USER CONTROL has a
text box <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>. How can
I get the text value from that text box (TextBox1 in NewWebUserControl1) in
the code behind of the page, i.e.<form id="form1" runat="server">.

Hope its clear enough now.
 
M

Mick Wilson

So I have <form id="form1" runat="server"> and that form has a "nested" web
user control by <%@ Register Src="Controls/NewWebUserControl1.ascx"
TagName="WebUserControl1"  TagPrefix="uc1" %>. That WEB USER CONTROL has a
text box  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>. How can
I get the text value from that text box (TextBox1 in NewWebUserControl1) in
the code behind of the page, i.e.<form id="form1" runat="server">.

You can access the controls collection of your nested user control
using its ID. In your page:

<uc:foo ID="foo" runat="server"></uc:NotesPanel>

In your codebehind:

foo.FindControl("myControl"), or something similar.

As an alternative, you might expose the value of your textbox as a
Property of the user control, if it makes sense in your application.
 
I

Igor

Appologies once again

How can I reference a specific control in a web user control from web form's
(page) code behind. In other words: I have a page (a web form) that has a
web user control in it. I want to read a value in code behind of that page
(web
form) from a text box in the web user control.

So I have <form id="form1" runat="server"> and that user form has a "nested"
web
user control by <%@ Register Src="Controls/NewWebUserControl1.ascx"
TagName="WebUserControl1" TagPrefix="uc1" %>. That WEB USER CONTROL has a
text box <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>. How can
I get the text value from that text box (TextBox1 in NewWebUserControl1) in
the code behind of the page, i.e.<form id="form1" runat="server">.
 
J

Juan T. Llibre

This article should help you :

http://www.odetocode.com/articles/116.aspx

There's several code examples of ways to find controls in it.





Igor said:
Appologies once again

How can I reference a specific control in a web user control from web form's
(page) code behind. In other words: I have a page (a web form) that has a
web user control in it. I want to read a value in code behind of that page (web form) from a text box in the web user
control.

So I have <form id="form1" runat="server"> and that user form has a "nested" web
user control by <%@ Register Src="Controls/NewWebUserControl1.ascx"
TagName="WebUserControl1" TagPrefix="uc1" %>. That WEB USER CONTROL has a
text box <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>. How can
I get the text value from that text box (TextBox1 in NewWebUserControl1) in
the code behind of the page, i.e.<form id="form1" runat="server">.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top