A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Dynamically Add User Control



 
 
Thread Tools Display Modes
  #1  
Old November 23rd, 2005, 10:54 AM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Dynamically Add User Control

Ive started a new thread as original seems to have dried up. I was replying
to Steven Cheng.

Steven

Im getting in a bit of a mess with this. What I want to end up with is a
set of controls for editing / displaying fields on a webform. I would like
to be able to dynamically add these controls to webforms as and when I need
them.

Initially I need three types of fields

ctlFieldReadOnly
ctlFieldEditable
ctlFieldEditableRequired

Each of these controls will consist of the following controls:

ctlFieldReadOnly: Label (lblLabel) and a label (lblValue) to display the
data
ctlFieldEditable: Label (lblLabel) and a textbox (txtValue - background
colour blue) to the display the data
ctlFieldEditableRequired: Label (lblLabel) and a textbox (txtValue -
background colour yellow) to the display the data.

Each of these controls needs to expose a Label property and a Value
property.
Each control should be able to be configured so the either, the Label
control is above the Value control, or the Label control appears to the Left
of the Value control.

Each form may contain any number of each type of control.

Ive been trying to develop along the following lines:
Create a Base control such as ctlField that must be inherited. This control
will contain the properties Label, Value, Width and HorizontalAlignment.
Im then trying to derive the required controls from this control. My derived
controls should add the relevant webcontrols ie Label to display the Value
for a ctlReadOnly control, a Textbox to display the Value for
ctlFieldEditable & ctlFieldEditableRequired controls.
Im getting various results ranging from no controls being displayed, not
being able to refer to controls in order to read/write values.

It would be very helpful if you could provide a small sample of how I might
get this sort of scenario to work (VB if possible - I know you prefer C#)


Terry



"Terry Holland" wrote in message
...
We meet again Steven.

Ive modified my code to remove the New keyword and added the LoadControl
method in my page to load the control and now the user control appears on
the screen.

Thanks

Terry Holland


"Steven Cheng[MSFT]" wrote in message
...
Hi Terry,

As for ASP.NET Usercontrol(ascx...), the Control instances are all
defined
in the .ascx template file(if not dynamically adding control...), so we
should not declare "New" for control reference like:

Protected WithEvents txt As New System.Web.UI.WebControls.TextBox

If you get error when not using "New", there must have something
incorrect
in our page or code logic. Would you also provide the ascx template
together with the code behind?

In addition, for dynamically adding Usercontrol onto aspx page, we should
use the Page.LoadControl method to load the "xxx.ascx" so as to create
the
UserControl instance and add it into Container control in each Page
Request....

If there're anything unclear, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Terry Holland"
| Subject: Dynamically adding custom control
| Date: Thu, 17 Nov 2005 21:28:24 -0000
| Lines: 149
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID:
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
| NNTP-Posting-Host: host10.harsco.com 209.183.189.10
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingc ontrols:13997
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
|
| Im trying to dynamically add a user control for a webform but it is not
| appearing when I run the form.
|
| I have pasted the code that I am using. Can someone advise what Im
doing
| wrong. My user control (ctlTextBox) contains one textbox. When I
dragged
| this onto the control, the line
|
| Protected WithEvents txt As System.Web.UI.WebControls.TextBox
|
| was added the declarations area of the code module. Without changing
this
| to
|
| Protected WithEvents txt As New System.Web.UI.WebControls.TextBox
|
| An error is generated on my page as soon as I hit the line
|
| .Text = "Tesing Control"
|
| Also, if I drag ctlTextBox onto my form at design time, it displays OK
|
|
| ==========================
| User Control Code
| ==========================
| Public Class ctlTextBox
| Inherits System.Web.UI.UserControl
|
| #Region " Web Form Designer Generated Code "
|
| 'This call is required by the Web Form Designer.
| System.Diagnostics.DebuggerStepThrough() Private Sub
| InitializeComponent()
|
| End Sub
|
| '################################################# ###########
| '## This is the code that was generated
| ############
| '## but without the New keyword, a runtime error is generated
| ############
| '## when I try to set the Text property on the page
| ############
| '################################################# ###########
| 'Protected WithEvents txt As System.Web.UI.WebControls.TextBox
| Protected WithEvents txt As New System.Web.UI.WebControls.TextBox
|
| 'NOTE: The following placeholder declaration is required by the Web
Form
| Designer.
| 'Do not delete or move it.
| Private designerPlaceholderDeclaration As System.Object
|
| Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles MyBase.Init
| 'CODEGEN: This method call is required by the Web Form Designer
| 'Do not modify it using the code editor.
| InitializeComponent()
| End Sub
|
| #End Region
|
| Public Property Width() As Integer
| Get
| Return txt.Width.Value
| End Get
| Set(ByVal Value As Integer)
| txt.Width = Unit.Pixel(Value)
| End Set
| End Property
|
| Public Property Text() As String
| Get
| Return txt.Text
| End Get
| Set(ByVal Value As String)
| txt.Text = Value
| End Set
| End Property
|
| Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles MyBase.Load
| 'Put user code to initialize the page here
| txt.CssClass = "Editable"
| End Sub
|
| End Class
| ===========================
| End User Control Code
| ===========================
|
|
| ===========================
| Page Code
| ===========================
| Public Class pgeTest
| Inherits System.Web.UI.Page
|
| #Region " Web Form Designer Generated Code "
|
| 'This call is required by the Web Form Designer.
| System.Diagnostics.DebuggerStepThrough() Private Sub
| InitializeComponent()
|
| End Sub
|
| Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
|
| 'NOTE: The following placeholder declaration is required by the Web
Form
| Designer.
| 'Do not delete or move it.
| Private designerPlaceholderDeclaration As System.Object
|
| Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles MyBase.Init
| 'CODEGEN: This method call is required by the Web Form Designer
| 'Do not modify it using the code editor.
| InitializeComponent()
| End Sub
|
| #End Region
|
| Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles MyBase.Load
| BuildControls()
| End Sub
|
|
| Sub BuildControls()
| Dim tb As New ctlTextBox
| With tb
| .Text = "Tesing Control"
| End With
| Panel1.Controls.Add(tb)
|
| Dim txt As New TextBox
| txt.Text = "Hello"
| Panel1.Controls.Add(txt)
|
| Dim lbl As New Label
| lbl.Text = "Label"
| Panel1.Controls.Add(lbl)
|
| End Sub
|
| End Class
| ===============================
| End of Page Code
| ===============================
|
|
|







  #2  
Old November 26th, 2005, 02:42 AM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Dynamically Add User Control

This has nothing to do with Microsoft Access. I suggest you find a more
appropriate news group.

--
Duane Hookom
MS Access MVP


"Terry Holland" wrote in message
...
Ive started a new thread as original seems to have dried up. I was
replying
to Steven Cheng.

Steven

Im getting in a bit of a mess with this. What I want to end up with is a
set of controls for editing / displaying fields on a webform. I would
like
to be able to dynamically add these controls to webforms as and when I
need
them.

Initially I need three types of fields

ctlFieldReadOnly
ctlFieldEditable
ctlFieldEditableRequired

Each of these controls will consist of the following controls:

ctlFieldReadOnly: Label (lblLabel) and a label (lblValue) to display the
data
ctlFieldEditable: Label (lblLabel) and a textbox (txtValue - background
colour blue) to the display the data
ctlFieldEditableRequired: Label (lblLabel) and a textbox (txtValue -
background colour yellow) to the display the data.

Each of these controls needs to expose a Label property and a Value
property.
Each control should be able to be configured so the either, the Label
control is above the Value control, or the Label control appears to the
Left
of the Value control.

Each form may contain any number of each type of control.

Ive been trying to develop along the following lines:
Create a Base control such as ctlField that must be inherited. This
control
will contain the properties Label, Value, Width and HorizontalAlignment.
Im then trying to derive the required controls from this control. My
derived
controls should add the relevant webcontrols ie Label to display the Value
for a ctlReadOnly control, a Textbox to display the Value for
ctlFieldEditable & ctlFieldEditableRequired controls.
Im getting various results ranging from no controls being displayed, not
being able to refer to controls in order to read/write values.

It would be very helpful if you could provide a small sample of how I
might
get this sort of scenario to work (VB if possible - I know you prefer C#)


Terry



"Terry Holland" wrote in message
...
We meet again Steven.

Ive modified my code to remove the New keyword and added the LoadControl
method in my page to load the control and now the user control appears on
the screen.

Thanks

Terry Holland


"Steven Cheng[MSFT]" wrote in message
...
Hi Terry,

As for ASP.NET Usercontrol(ascx...), the Control instances are all
defined
in the .ascx template file(if not dynamically adding control...), so we
should not declare "New" for control reference like:

Protected WithEvents txt As New System.Web.UI.WebControls.TextBox

If you get error when not using "New", there must have something
incorrect
in our page or code logic. Would you also provide the ascx template
together with the code behind?

In addition, for dynamically adding Usercontrol onto aspx page, we
should
use the Page.LoadControl method to load the "xxx.ascx" so as to create
the
UserControl instance and add it into Container control in each Page
Request....

If there're anything unclear, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Terry Holland"
| Subject: Dynamically adding custom control
| Date: Thu, 17 Nov 2005 21:28:24 -0000
| Lines: 149
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID:
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
| NNTP-Posting-Host: host10.harsco.com 209.183.189.10
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingc ontrols:13997
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
|
| Im trying to dynamically add a user control for a webform but it is
not
| appearing when I run the form.
|
| I have pasted the code that I am using. Can someone advise what Im
doing
| wrong. My user control (ctlTextBox) contains one textbox. When I
dragged
| this onto the control, the line
|
| Protected WithEvents txt As System.Web.UI.WebControls.TextBox
|
| was added the declarations area of the code module. Without changing
this
| to
|
| Protected WithEvents txt As New System.Web.UI.WebControls.TextBox
|
| An error is generated on my page as soon as I hit the line
|
| .Text = "Tesing Control"
|
| Also, if I drag ctlTextBox onto my form at design time, it displays OK
|
|
| ==========================
| User Control Code
| ==========================
| Public Class ctlTextBox
| Inherits System.Web.UI.UserControl
|
| #Region " Web Form Designer Generated Code "
|
| 'This call is required by the Web Form Designer.
| System.Diagnostics.DebuggerStepThrough() Private Sub
| InitializeComponent()
|
| End Sub
|
| '################################################# ###########
| '## This is the code that was generated
| ############
| '## but without the New keyword, a runtime error is generated
| ############
| '## when I try to set the Text property on the page
| ############
| '################################################# ###########
| 'Protected WithEvents txt As System.Web.UI.WebControls.TextBox
| Protected WithEvents txt As New System.Web.UI.WebControls.TextBox
|
| 'NOTE: The following placeholder declaration is required by the
Web
Form
| Designer.
| 'Do not delete or move it.
| Private designerPlaceholderDeclaration As System.Object
|
| Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles MyBase.Init
| 'CODEGEN: This method call is required by the Web Form
Designer
| 'Do not modify it using the code editor.
| InitializeComponent()
| End Sub
|
| #End Region
|
| Public Property Width() As Integer
| Get
| Return txt.Width.Value
| End Get
| Set(ByVal Value As Integer)
| txt.Width = Unit.Pixel(Value)
| End Set
| End Property
|
| Public Property Text() As String
| Get
| Return txt.Text
| End Get
| Set(ByVal Value As String)
| txt.Text = Value
| End Set
| End Property
|
| Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles MyBase.Load
| 'Put user code to initialize the page here
| txt.CssClass = "Editable"
| End Sub
|
| End Class
| ===========================
| End User Control Code
| ===========================
|
|
| ===========================
| Page Code
| ===========================
| Public Class pgeTest
| Inherits System.Web.UI.Page
|
| #Region " Web Form Designer Generated Code "
|
| 'This call is required by the Web Form Designer.
| System.Diagnostics.DebuggerStepThrough() Private Sub
| InitializeComponent()
|
| End Sub
|
| Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
|
| 'NOTE: The following placeholder declaration is required by the
Web
Form
| Designer.
| 'Do not delete or move it.
| Private designerPlaceholderDeclaration As System.Object
|
| Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles MyBase.Init
| 'CODEGEN: This method call is required by the Web Form
Designer
| 'Do not modify it using the code editor.
| InitializeComponent()
| End Sub
|
| #End Region
|
| Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles MyBase.Load
| BuildControls()
| End Sub
|
|
| Sub BuildControls()
| Dim tb As New ctlTextBox
| With tb
| .Text = "Tesing Control"
| End With
| Panel1.Controls.Add(tb)
|
| Dim txt As New TextBox
| txt.Text = "Hello"
| Panel1.Controls.Add(txt)
|
| Dim lbl As New Label
| lbl.Text = "Label"
| Panel1.Controls.Add(lbl)
|
| End Sub
|
| End Class
| ===============================
| End of Page Code
| ===============================
|
|
|









  #3  
Old November 28th, 2005, 08:48 AM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Dynamically Add User Control

Hi Terry,

Steven has replied this thread in
microsoft.public.dotnet.framework.aspnet.buildingc ontrols. Pleaes reply his
post in that thread. If you have any questions or concerns, please feel
free to let me know.

Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are always here to be of
assistance!


Sincerely yours,

Michael Cheng
Microsoft Online Partner Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Toolbars, Drop-Down Menus Rick New Users 1 September 21st, 2005 11:17 AM
Setting rowsource of chart dynamically, with user security in place Tony M Setting Up & Running Reports 0 September 10th, 2005 12:57 AM
Having trouble with multi-select list box in Access brandelfly New Users 4 February 10th, 2005 07:36 PM
Inserting a User Control in PowerPoint Aaron Powerpoint 0 June 22nd, 2004 11:52 PM
Dynamically control how many lines on a graph? Keith R Charts and Charting 2 October 22nd, 2003 04:19 PM


All times are GMT +1. The time now is 08:33 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.