For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > June 2008 > Retreiving a value from Web User Control









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Retreiving a value from Web User Control
Igor

2008-06-13, 8:41 am

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

Munna

2008-06-13, 8:41 am

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
Igor

2008-06-13, 7:35 pm

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.




"Munna" <munnaonc@gmail.com> wrote in message
news:d4d4462d-b829-4ed0-b5c2-10939f2c8a55@a1g2000hsb.googlegroups.com...
> 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


Mark Rae [MVP]

2008-06-13, 7:35 pm

"Igor" <igorm@live.com> wrote in message
news:524B7257-D350-45FF-8E25-64D2261BDD04@microsoft.com...

> How can I reference a specific control in a web user form


Can you please clarify what you mean by "web user form"... Do you mean a
UserControl...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mick Wilson

2008-06-13, 7:35 pm

On Jun 13, 9:15=A0am, "Igor" <ig...@live.com> wrote:
> So I have <form id=3D"form1" runat=3D"server"> and that form has a "nested=

" web
> user control by <%@ Register Src=3D"Controls/NewWebUserControl1.ascx"
> TagName=3D"WebUserControl1" =A0TagPrefix=3D"uc1" %>. That WEB USER CONTROL=

has a
> text box =A0<asp:TextBox ID=3D"TextBox1" runat=3D"server"></asp:TextBox>. =

How can
> I get the text value from that text box (TextBox1 in NewWebUserControl1) i=

n
> the code behind of the page, i.e.<form id=3D"form1" runat=3D"server">.
>


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

<uc:foo ID=3D"foo" runat=3D"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.
Igor

2008-06-13, 7:35 pm

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">.




"Mark Rae [MVP]" <mark@markNOSPAMrae.net> wrote in message
news:O8cgO4VzIHA.5816@TK2MSFTNGP02.phx.gbl...
> "Igor" <igorm@live.com> wrote in message
> news:524B7257-D350-45FF-8E25-64D2261BDD04@microsoft.com...
>
>
> Can you please clarify what you mean by "web user form"... Do you mean a
> UserControl...?
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net


Juan T. Llibre

2008-06-13, 7:35 pm

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" <igorm@live.com> wrote in message news:C5F7C3FD-A3FC-43B0-872E-A51EAE4E1B6D@microsoft.com...
> 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">.
>
>
>
>
> "Mark Rae [MVP]" <mark@markNOSPAMrae.net> wrote in message news:O8cgO4VzIHA.5816@TK2MSFTNGP02.phx.gbl...
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com