Building composite server control

Discussion in 'ASP .Net Building Controls' started by thomas, May 9, 2004.

  1. thomas

    thomas Guest

    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

    Thanks in advance!!
    thomas, May 9, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sleigh
    Replies:
    1
    Views:
    2,684
    sleigh
    Feb 12, 2004
  2. Aaron Prohaska

    Composite control building architecture problem

    Aaron Prohaska, Dec 4, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    184
    Aaron Prohaska
    Dec 4, 2003
  3. thomas

    Building simple datascource driven composite control

    thomas, May 7, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    106
    thomas
    May 7, 2004
  4. thomas
    Replies:
    0
    Views:
    134
    thomas
    May 7, 2004
  5. Chad
    Replies:
    0
    Views:
    219
Loading...

Share This Page