Retreiving a value from Web User Control

Discussion in 'ASP .Net' started by Igor, Jun 13, 2008.

  1. Igor

    Igor Guest

    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
    Igor, Jun 13, 2008
    #1
    1. Advertising

  2. Igor

    Munna Guest

    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
    Munna, Jun 13, 2008
    #2
    1. Advertising

  3. Igor

    Igor Guest

    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" <> wrote in message
    news:...
    > 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, Jun 13, 2008
    #3
  4. Igor

    Mick Wilson Guest

    On Jun 13, 9:15 am, "Igor" <> wrote:
    > 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.
    Mick Wilson, Jun 13, 2008
    #4
  5. Igor

    Igor Guest

    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]" <> wrote in message
    news:...
    > "Igor" <> wrote in message
    > news:...
    >
    >> 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
    Igor, Jun 13, 2008
    #5
  6. 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" <> wrote in message news:...
    > 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]" <> wrote in message news:...
    >> "Igor" <> wrote in message news:...
    >>
    >>> 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

    >
    Juan T. Llibre, Jun 13, 2008
    #6
    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. Reny J Joseph Thuthikattu
    Replies:
    1
    Views:
    554
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=
    Dec 30, 2004
  2. Mark Siffer
    Replies:
    3
    Views:
    5,762
    Karl Seguin
    Mar 30, 2005
  3. Replies:
    0
    Views:
    384
  4. James Pemberton

    Problem retreiving value in javascript

    James Pemberton, Aug 17, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    6,246
    James Pemberton
    Aug 17, 2006
  5. ElCapitan
    Replies:
    0
    Views:
    131
    ElCapitan
    Mar 14, 2006
Loading...

Share This Page