Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Composite Web Control - Property window

Status
Not open for further replies.

nscheu

Technical User
Sep 10, 2001
10
0
0
US
Hello,

I am creating a composite web control and I am having difficultly displaying the properties of the controls that I have added.

I have two web controls within my composite web control, a Calendar control and an ImageButton control. The point of the composite web control is when the image button is clicked it opens up a calendar and the user can select a date which will populate a textbox that was specified.

The problem I am having is that I cannot get all the properties for the Calendar control or the Image Button control to be displayed. I want to be able to let the developer have full control when using this composite web control. For example they should be able to change DayHeaderStyle, DayStyle, SelectedDayStyle, etc in the properties window for the calendar (also properties specific to the Image Button).

I would think that it would be possible to display all the properties for the controls that were added to the custom composite control but I cannot seem to figure it out. Thanks in advance for any help.


 
Add the properties to the custom control that you want the user to control.

And set the property of the calender control or any other controls within the custom control. Just have a look at the code below:

Imports System.Web.UI.WebControls
Imports System.Web.UI
Imports System.Web

Public Class Adder
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer

Dim tbFirst As TextBox
Dim tbSecond As TextBox
Dim tbResult As TextBox
Dim WithEvents btnEval As Button

Sub New()
MyBase.New()
Me.Width = Unit.Pixel(300)
End Sub

Protected Overrides Sub CreateChildCOntrols()
tbFirst = New TextBox
tbSecond = New TextBox
Dim litAdd As New Literal
btnEval = New Button
tbResult = New TextBox

litAdd.Text = " + "
btnEval.Text = " = "
tbResult.ReadOnly = True

Controls.Add(tbFirst)
Controls.Add(litAdd)
Controls.Add(tbSecond)
Controls.Add(btnEval)
Controls.Add(tbResult)

End Sub

Protected Overrides Sub render(ByVal output As HtmlTextWriter)
EnsureChildControls()
RenderChildren(output)
End Sub

Private Sub btnEval_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnEval.Click
EnsureChildControls()
Try
Dim result As Double = CDbl(tbFirst.Text) + CDbl(tbSecond.Text)
tbResult.Text = result.ToString
Catch ex As Exception
End Try
End Sub

Property result() As Double
Get
EnsureChildControls()
Try
Return CDbl(tbResult.Text)
Catch ex As Exception
Return 0
End Try
End Get
Set(ByVal Value As Double)
EnsureChildControls()
tbResult.Text = Value.ToString
End Set
End Property

End Class

By using result property you can set the text of tbResult TextBox. In the same way create property procedures for DayHeaderStyle, DayStyle, SelectedDayStyle, etc.

 
Thanks for the quick response.

I still am a little confused however. From the message it seems as though you would have to use the result property for every single property that you would want to set in the control that you are using. Am I incorrect in saying that?

It seems as though if you are using a pre-existing control in a composite control you should just be able to add all the properties for that control to your properties window with just a few lines of code.

Also, just and FYI I am attempting to develop this control using C#.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top