User control

  • Thread starter Thread starter Mark Goldin
  • Start date Start date
M

Mark Goldin

I'd like to create a user control (Label and Text box) and modify every
instance of that control
when I add it to a web page. How can I do that?
 
not 100% clear on what it is you want to do, but I think what you want to do
is expose public properties in your user control, you can then set the
properties either in the designer:

<myControl:control id="x" runat="server" ShowTextBox="True" showLabel="True"
LabelText="blah" />

or in code:

x.ShowTextBox = True
x.ShowLabel = true
x.LabelText = "blah"

The control itself would look something like:

Public Class test
Inherits System.Web.UI.UserControl

Private _showTextBox As Boolean
Public Property ShowTextBox() As Boolean
Get
Return _showTextBox
End Get
Set(ByVal Value As Boolean)
_showTextBox = Value
End Set
End Property


....
End class
 
You do that the same way you modify a single instance of that Control,
except that you do the same for every instance.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
The way you need to do is write properties for the user control that
internally set the label or text box values.
these properties will be displayed when you select property window of the
control.
 
I'm not sure what you mean by "individual controls of that user control."
Your original post asked how to modify every instance of a single Control.
So, what exactly ARE you asking? Are you asking if you can set properties of
every instance of a Control, or are you asking how to modify the properties
of the child Controls of a given single instance of a User Control?

I can tell you this much at this point: A User Control is a class. Classes
have properties. You can set the public properties which have a Set method,
and public fields, the same ways that you would set properties and fields of
any class. To modify properties of any Control in its Controls Collection,
you just use FindControl() to get a handle to the child Control, and then
set the properties of the Child Control to whatever you want.

I'm not sure, but I'm getting the impression that you want to do everything
through the Visual Studio.Net IDE. That is not possible. Some things have to
be hand-coded.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top