Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2005, 01:20 PM
Authorized User
 
Join Date: May 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old June 23rd, 2005, 09:58 PM
Authorized User
 
Join Date: May 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe my answer could lie here:
http://authors.aspalliance.com/artic...icbuttons.aspx

and that because my dropdown (and button) is created dynamically, there is no reference to them when the page loads (to add the event)? Does this sound correct?

Thanks








Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is addhandler for linkbutton.click not working rsearing ASP.NET 2.0 Basics 7 November 12th, 2007 06:06 PM
addhandler catch 22 roog ASP.NET 1.0 and 1.1 Professional 2 February 20th, 2006 01:01 PM
Beware the AddHandler etoostr General .NET 0 November 6th, 2004 05:53 PM
How to include c# class and vb class in the .vbprj umeshayk VS.NET 2002/2003 2 January 9th, 2004 12:08 AM
AddHandler from String [email protected] Pro VB.NET 2002/2003 2 July 6th, 2003 04:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.