Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Building simple datascource driven composite control - Full post

Reply
Thread Tools

Building simple datascource driven composite control - Full post

 
 
thomas
Guest
Posts: n/a
 
      05-07-2004
Hello All,

Im trying to build a simple datascource driven control, but im having
problems, maybe someone here can set me off in the right direction.

I would like to build a control that displays linkbuttons based on captions
in an array as datasource.

I have 2 problems with the control:

1. (For testpurposes) displaying 10 controls and capturing events.

Example (my control class Implements INamingContainer)

Protected Overrides Sub CreateChildControls()
For i As Integer = 1 To 10

LinkButton = New LinkButton

LinkButton.Text = "link " + CStr(i)

Controls.Add(LinkButton)

Next

End Sub

Private Sub LinkButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles LinkButton.Click

RaiseEvent Click(sender, e)

End Sub

Event Click(ByVal sender As Object, ByVal e As EventArgs)


My linkbutons are shown but the event for the clicked button is lost in
postback ?? I tried with 3 controls and it worked ????



2. Setting source for my control And displaying liknbuttons based on strings
in an array.

I have implemented a datasource property in my control with the type
string()

In my Webform1.aspx test page i set the data source

Dim MyArray As String() = {"test1", "test2", "test3", "test4", "test5"}
MyControl..DataSource = MyArray

The first time my control loads the linkbutton are displayed with the right
captions, when i click a linkbutton and the page postback the
CreateChildControls is called and an exeption is thrown because the
datacource is not set. I have tried different solutions but no luck. What am
i missing in the event model for composite controls?? Am i using the wrong
strategy should i base my composite control on a repeater control or ???

Protected Overrides Sub CreateChildControls()
For i As Integer = 0 To _DataSource.Length - 1
LinkButton = New LinkButton

LinkButton.Text = "link " + CStr(i)

Controls.Add(LinkButton)

Next i

end sub








 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Losing Composite Control property that another Composite Control ... Chad ASP .Net Building Controls 0 02-01-2005 09:01 PM
Possible to create a composite control that has a child control that is a validator that validates the composite control itself? Jonathan Eric Miller ASP .Net Building Controls 2 07-22-2004 10:58 PM
Building simple datascource driven composite control thomas ASP .Net Building Controls 0 05-07-2004 11:51 AM
Composite control with dynamic composite controls sleigh ASP .Net 1 02-12-2004 06:24 PM
Composite control building architecture problem Aaron Prohaska ASP .Net Building Controls 0 12-04-2003 07:04 PM



Advertisments