AddHandler in class
Hi again
I'm embarking on something new, the AddHandler, and I'm not having much joy. I'm therefore hoping that someone can help me with this and tell me what I'm doing wrong (or missing out) to make the AddHandler work within my control. (I have scoured the web high and low and can't find anything which helps or explains the AddHandler in an example that I can get to work!).
Here is what I am trying to do (theoretically): I've created a control, which gets available Room Types from a database and populates a dropdown list. Once the dropdown list is populated, I want the user to be able to select a specific room type, and for it then to query my database for that specific room type.
However, because I couldn't seem to get the control to raise the event at all, I simplified my code to a simple Response.write (on SelectIndexChanged) or a simple Response.Redirect (on Click) - as you'll see in the code below (need to emphasize that the code below is not my final intended code, I want it to do something more beyond writing or redirecting...)
************************************************** *************
Public Class RoomType
Inherits Control
Private tcode As New TourCodes
Private _strTourCode As String
Private _ddlRoomTypes As New DropDownList ' The dropdown list
Private dlistRooms As DataList
Public Sub New()
End Sub
Protected Overrides Sub CreateChildControls()
With _ddlRoomTypes
.id = "ddlRoomTypes"
.AutoPostBack = True
.datasource = data.getDDRoomTypes
.DataTextField = "Key"
.dataValueField = "Value"
.DataBind()
End With
AddHandler _ddlRoomTypes.SelectedIndexChanged, AddressOf ddlRoomTypes_Changed
Controls.Add(_ddlRoomTypes)
Dim btnClickme As New Button 'couldn't get dropdown to work so I added a
btnClickme.id = "btnClickme" 'button and attempted to get that to work
btnClickme.Text="Click here"
AddHandler btnClickme.Click, AddressOf ddlRoomTypes_Clicked
Controls.Add(btnClickme)
End Sub
Private Sub ddlRoomTypes_Changed(Sender As Object, E As EventArgs)
Current.Response.Write("hello")
End Sub
Private Sub ddlRoomTypes_Clicked(Sender As Object, E As EventArgs)
Current.Response.Redirect("hello.htm")
End Sub
Protected Overrides Sub Render(writer As HtmlTextWriter)
writer.write("<div class=""lboxhead"">")
writer.write("Rooms")
writer.write("</div>")
writer.write("<div class=""lboxmain"">")
writer.write("Use the dropdown below to select a specific room type<br />")
FindControl("ddlRoomTypes").RenderControl(writer)
writer.write("<br /><br />")
FindControl("btnClickme").RenderControl(writer)
writer.write("</div>")
End Sub
End Class
************************************************** *****************
As ever, I will be eternally grateful for any advice or help, and even more grateful when I can get it to work!
Thanks
Shane
|