Retreiving a value from Web User Control

  • Thread starter Thread starter Igor
  • Start date Start date
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
 
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
 
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.
 
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 CONTROLhas 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.
 
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">.
 
This article should help you :

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

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




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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">.
 
Back
Top