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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Web custom control handling events

Status
Not open for further replies.

Govnor

Technical User
Sep 3, 2002
55
GB
Hi,

I have started creating a navigation control using a web custom control.

My navigation control consists of 5-buttons vertical aligned.
i.e.
BUTTON1
BUTTON2
BUTTON3
BUTTON4
BUTTON5

What I WANT to happen is when I click one of these buttons the buttons move apart and links are displayed using a repeater connected to a SQL database.
i.e. – Button 2 is clicked to reveal links
BUTTON1
BUTTON2
Link1
Link2
Link3
Link4
BUTTON3
BUTTON4
BUTTON5

I know the SQL scripts and how to use a repeater.

My problems are handling an event from the button click on a web custom control and also a method to re render the web custom control to display the links.

Any help or guidance will be much appreciated.

Thanks
Manraj



CODE BELOW:

-- Import statements here

Namespace CustomNavBar

<DefaultProperty("Text"), ToolboxData("<{0}:CustomNavBar runat=server></{0}:CustomNavBar>")> Public Class CustomNavBar
Inherits System.Web.UI.WebControls.WebControl

Dim _text As String
Dim btnPressed As String
Protected WithEvents btnHome As Button
-- more protected statement here
Protected WithEvents lblError As Label
Protected WithEvents rptNavigation As Repeater

<Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
Get
Return _text
End Get

Set(ByVal Value As String)
_text = Value
End Set
End Property

Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
output.WriteFullBeginTag("Table width=100% height=100%")
output.WriteFullBeginTag("TR")
output.WriteFullBeginTag("TD bgColor=#3399ff vAlign=top")
btnHome.RenderControl(output)
Select Case btnPressed
Case btnHome.Text
output.WriteFullBeginTag("br")
rptNavigation.RenderControl(output)
output.WriteFullBeginTag("ItemTemplate")
output.WriteFullBeginTag("a href='<%# DataBinder.Eval(Container.DataItem, 'LOCATION') %>")
output.Write("<%# DataBinder.Eval(Container.DataItem, 'NAME') %>")
output.WriteEndTag("a")

output.WriteFullBeginTag("br")
btnMyProfile.RenderControl(output)
output.WriteFullBeginTag("br")
btnSchedule.RenderControl(output)
output.WriteFullBeginTag("br")
btnPersonnel.RenderControl(output)
output.WriteFullBeginTag("br")
btnHelp.RenderControl(output)
output.WriteFullBeginTag("br")
btnApplications.RenderControl(output)
output.WriteFullBeginTag("br")
btnLaw.RenderControl(output)
output.WriteFullBeginTag("br")
btnMaintenace.RenderControl(output)
-- more case statement here
Case Else
output.WriteFullBeginTag("br")
btnMyProfile.RenderControl(output)
output.WriteFullBeginTag("br")
btnSchedule.RenderControl(output)
output.WriteFullBeginTag("br")
btnPersonnel.RenderControl(output)
output.WriteFullBeginTag("br")
btnHelp.RenderControl(output)
output.WriteFullBeginTag("br")
btnApplications.RenderControl(output)
output.WriteFullBeginTag("br")
btnLaw.RenderControl(output)
output.WriteFullBeginTag("br")
btnMaintenace.RenderControl(output)
End Select

output.WriteFullBeginTag("br")
lblError.RenderControl(output)
output.WriteEndTag("TD")
output.WriteEndTag("TR")
output.WriteEndTag("Table")
output.Flush()

End Sub

Protected Overrides Sub CreateChildControls()
btnHome = New Button
With btnHome
.ID = "btnHome"
.BorderWidth = Unit.Pixel(2)
.BorderColor = Color.DarkBlue
.BackColor = Color.SteelBlue
.Font.Bold = True
.Font.Name = "Arial"
.Font.Size = FontUnit.Point(12)
.Height = Unit.Pixel(29)
.Width = Unit.Percentage(100)
.Text = "Home"
End With
-- more creation of buttons here
rptNavigation = New Repeater
With rptNavigation
.ID = "rptNavigation"
End With
lblError = New Label
With lblError
.ID = "lblError"
.Text = "Error information will be displayed here"
.Height = Unit.Percentage(100)
.Width = Unit.Percentage(100)
End With


Me.Controls.Add(btnHome)
Me.Controls.Add(rptNavigation)
Me.Controls.Add(lblError)
-- more adds to control here

End Sub
Public Sub New()
MyBase.new()
End Sub

Private Sub btnHome_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHome.Click
-- Here I will connect to a database and populate the repeater (more code here)
conn.Open()
rptNavigation.DataSource = command.ExecuteReader()
rptNavigation.DataBind()
conn.Close()
End Sub

End Class

End Namespace


THE GOV' NOR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top