ASP.NET user controls


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: ASP.NET user controls

  1. #1
    Thai Guest

    ASP.NET user controls


    Hello,

    I am having problems trying to use a UserControl in asp.net. I created the
    control, then in my web form I added the following code to add the control:

    -- code --
    Control uc;

    uc = LoadControl("MyControl.ascx");

    this.phUserControl.Controls.Add(uc); // added the control to the placeholder
    -- end code --


    Ok, now the control is added, the control has an input text box named TextBox1.
    My webform has a button (btnSave), how can I have my btnSave's onclick event
    read the TextBox1.Text from the UserControl? Before you ask why I don't
    want to put the Save button on the user control, its because I will have
    different controls on the form and the save button will read all of them.

    Please help if you can.

    Thanks.
    Thai


  2. #2
    bardi paolo Guest

    Re: ASP.NET user controls


    "Thai" <thai21@hotmail.com> wrote:
    >
    >Hello,
    >
    >I am having problems trying to use a UserControl in asp.net. I created

    the
    >control, then in my web form I added the following code to add the control:
    >
    >-- code --
    >Control uc;
    >
    >uc = LoadControl("MyControl.ascx");
    >
    >this.phUserControl.Controls.Add(uc); // added the control to the placeholder
    >-- end code --
    >
    >
    >Ok, now the control is added, the control has an input text box named TextBox1.
    > My webform has a button (btnSave), how can I have my btnSave's onclick

    event
    >read the TextBox1.Text from the UserControl? Before you ask why I don't
    >want to put the Save button on the user control, its because I will have
    >different controls on the form and the save button will read all of them.
    >
    >Please help if you can.
    >
    >Thanks.
    >Thai
    >

    just declare a property of your user control that returns the textbox text.
    Then, in the page, read the property.


  3. #3
    Tim Guest

    Re: ASP.NET user controls


    "bardi paolo" <bardi@movitrack.it> wrote:
    >
    >"Thai" <thai21@hotmail.com> wrote:
    >>
    >>Hello,
    >>
    >>I am having problems trying to use a UserControl in asp.net. I created

    >the
    >>control, then in my web form I added the following code to add the control:
    >>
    >>-- code --
    >>Control uc;
    >>
    >>uc = LoadControl("MyControl.ascx");
    >>
    >>this.phUserControl.Controls.Add(uc); // added the control to the placeholder
    >>-- end code --
    >>
    >>
    >>Ok, now the control is added, the control has an input text box named TextBox1.
    >> My webform has a button (btnSave), how can I have my btnSave's onclick

    >event
    >>read the TextBox1.Text from the UserControl? Before you ask why I don't
    >>want to put the Save button on the user control, its because I will have
    >>different controls on the form and the save button will read all of them.
    >>
    >>Please help if you can.
    >>
    >>Thanks.
    >>Thai
    >>

    >just declare a property of your user control that returns the textbox text.
    >Then, in the page, read the property.
    >


    How do you read the property in from the user control?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center