Results 1 to 2 of 2

Thread: usercontrols

  1. #1
    Join Date
    Dec 1969

    Default usercontrols

    Hello, <BR><BR>I am having problems trying to use a UserControl in I created the control, then in my web form I added the following code to add the control: <BR><BR>-- code -- <BR>Control uc; <BR><BR>uc = LoadControl("MyControl.ascx"); <BR><BR>this.phUserControl.Controls.Add(uc); // added the control to the placeholder <BR>-- end code -- <BR><BR><BR>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&#039;s onclick event read the TextBox1.Text from the UserControl? Before you ask why I don&#039;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. <BR><BR>Please help if you can. <BR><BR>Thanks. <BR>Thai<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: usercontrols

    You have to expose the text property of the textbox through a usercontrol property.<BR><BR>In your user control add the code:<BR>Public Property TextBox1Text as string<BR> Get<BR> Return TextBox1.Text<BR> End Get<BR> Set(ByVal Value as String)<BR> TextBox1.Text = Value<BR> End Set<BR>End Property<BR><BR>If you don&#039;t want to be able to set the textbox, then just make it readonly and remove the set portion.<BR><BR>In your btnSave&#039;s onclick event now you can access uc.TextBox1Text.<BR><BR>Hope that helps.<BR>Sara

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts