Simple composite control fires event fires first time but not second

Discussion in 'ASP .Net Web Controls' started by sellars.paul@googlemail.com, May 11, 2009.

  1. Guest

    Hello,

    I have a simple composite control (asp.net 1.1). The on click event
    fires the first time the button is clicked but not on subsequest
    clicks. Any ideas why please?


    Imports System.ComponentModel
    Imports System.Collections.Specialized
    Imports System.Web.UI
    Imports System.Web
    Imports System.Web.UI.WebControls
    Imports Microsoft.ContentManagement.Common
    Imports Microsoft.ContentManagement.Publishing
    Imports System.Web.UI.WebControls.WebControl
    Imports Microsoft.ContentManagement.WebControls.Design
    Imports Microsoft.ContentManagement.WebControls

    <ToolboxData("<{0}:TopNavMenuComp runat=server></{0}:TopNavMenuComp>")
    > _

    Public Class TopNavMenuComp
    Inherits Control
    Implements INamingContainer

    Private _SearchTerm As TextBox
    Private _GoSearch As Button

    Protected Overrides Sub createchildcontrols()

    Controls.Clear()

    _GoSearch = New Button
    _SearchTerm = New TextBox
    _SearchTerm.ID = "searchtermID"
    _GoSearch.Text = "Go Search"
    _GoSearch.ID = "mysearchID"

    With Me.Controls
    .Add(_SearchTerm)
    .Add(_GoSearch)
    End With

    AddHandler _GoSearch.Click, New EventHandler(AddressOf
    Me.OnSearchClick)

    ensurechildcontrols()


    End Sub

    Private Sub OnSearchClick(ByVal sender As Object, ByVal e As
    EventArgs)

    Dim buttonclicked As String

    buttonclicked = _SearchTerm.Text

    End Sub



    There is then a render

    Protected Overrides Sub Render(ByVal output As
    System.Web.UI.HtmlTextWriter)

    that includes the lines:

    _SearchTerm.RenderControl(output)
    _GoSearch.RenderControl(output)


    Regards,
    Paul
     
    , May 11, 2009
    #1
    1. Advertising

  2. <ToolboxData("<{0}:TopNavMenuComp runat=server></{0}:TopNavMenuComp>")>
    _
    Public Class TopNavMenuComp
    Inherits CompositeControl

    Protected Overrides Sub createchildcontrols()
    MyBase.Controls.Clear()
    Dim _SearchTerm As New TextBox
    With _SearchTerm
    .ID = "searchtermID"
    End With
    MyBase.Controls.Add(_SearchTerm)

    Dim _GoSearch As New Button
    With _GoSearch
    .ID = "mysearchID"
    .Text = "Go Search"
    AddHandler .Click, AddressOf Me.OnSearchClick
    End With
    MyBase.Controls.Add(_GoSearch)
    End Sub

    Private Sub OnSearchClick(ByVal sender As Object, ByVal e As
    System.EventArgs)
    Dim _SearchTerm As TextBox =
    TryCast(Me.FindControl("_SearchTerm"), TextBox)
    If _SearchTerm IsNot Nothing Then
    Dim buttonclicked As String = _SearchTerm.Text
    End If
    End Sub

    End Class

    Hope that helps!


    <> wrote in message
    news:...
    > Hello,
    >
    > I have a simple composite control (asp.net 1.1). The on click event
    > fires the first time the button is clicked but not on subsequest
    > clicks. Any ideas why please?
    >
    >
    > Imports System.ComponentModel
    > Imports System.Collections.Specialized
    > Imports System.Web.UI
    > Imports System.Web
    > Imports System.Web.UI.WebControls
    > Imports Microsoft.ContentManagement.Common
    > Imports Microsoft.ContentManagement.Publishing
    > Imports System.Web.UI.WebControls.WebControl
    > Imports Microsoft.ContentManagement.WebControls.Design
    > Imports Microsoft.ContentManagement.WebControls
    >
    > <ToolboxData("<{0}:TopNavMenuComp runat=server></{0}:TopNavMenuComp>")
    >> _

    > Public Class TopNavMenuComp
    > Inherits Control
    > Implements INamingContainer
    >
    > Private _SearchTerm As TextBox
    > Private _GoSearch As Button
    >
    > Protected Overrides Sub createchildcontrols()
    >
    > Controls.Clear()
    >
    > _GoSearch = New Button
    > _SearchTerm = New TextBox
    > _SearchTerm.ID = "searchtermID"
    > _GoSearch.Text = "Go Search"
    > _GoSearch.ID = "mysearchID"
    >
    > With Me.Controls
    > .Add(_SearchTerm)
    > .Add(_GoSearch)
    > End With
    >
    > AddHandler _GoSearch.Click, New EventHandler(AddressOf
    > Me.OnSearchClick)
    >
    > ensurechildcontrols()
    >
    >
    > End Sub
    >
    > Private Sub OnSearchClick(ByVal sender As Object, ByVal e As
    > EventArgs)
    >
    > Dim buttonclicked As String
    >
    > buttonclicked = _SearchTerm.Text
    >
    > End Sub
    >
    >
    >
    > There is then a render
    >
    > Protected Overrides Sub Render(ByVal output As
    > System.Web.UI.HtmlTextWriter)
    >
    > that includes the lines:
    >
    > _SearchTerm.RenderControl(output)
    > _GoSearch.RenderControl(output)
    >
    >
    > Regards,
    > Paul
    >
     
    William Niver, May 12, 2009
    #2
    1. Advertising

  3. Guest

    Re: Simple composite control fires event fires first time but notsecond

    Hello William,

    Thank you for the response. The problem is that the on click event is
    not firing. The control is for a search box that can be dropped onto
    every page, when a search term is supplied there is a redirect to the
    search page (where we use google mini to do the search). The first
    time I start the application it behaves as I would expect - the
    OnSearchClick sub happens. I then click the button a second time and
    it does not happen.

    I see your code inhertits from compositecontrol. I think this is
    asp.net 2.0, unfortunately we are still on asp.net 1.1.

    Regards,
    Paul
     
    , May 12, 2009
    #3
  4. Guest

    Re: Simple composite control fires event fires first time but notsecond

    Hello,

    Found cause of problem. The page on which the control was placed had
    cacheing turned on:

    <%@ Outputcache duration="300" location="server" varybyparam="none"
    varybycustom="cmsposting"%>

    When I turned off the caching it worked fine.

    Paul


    On 12 May, 09:54, wrote:
    > Hello William,
    >
    > Thank you for the response. The problem is that the on click event is
    > not firing. The control is for a search box that can be dropped onto
    > every page, when a search term is supplied there is a redirect to the
    > search page (where we use google mini to do the search). The first
    > time I start the application it behaves as I would expect - the
    > OnSearchClick sub happens. I then click the button a second time and
    > it does not happen.
    >
    > I see your code inhertits from compositecontrol. I think this is
    > asp.net 2.0, unfortunately we are still on asp.net 1.1.
    >
    > Regards,
    > Paul
     
    , May 13, 2009
    #4
    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. =?Utf-8?B?T2JpIE9iZXJvaQ==?=

    Submit_click event fires only the first time the button is clicked

    =?Utf-8?B?T2JpIE9iZXJvaQ==?=, Sep 1, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    618
    Kevin Spencer
    Sep 1, 2005
  2. Chad
    Replies:
    0
    Views:
    254
  3. Brian Takita
    Replies:
    2
    Views:
    154
    Brian Takita
    Jul 25, 2005
  4. http://links.i6networks.com

    Why '' Is Matched First Time, Not Second Time

    http://links.i6networks.com, Aug 21, 2004, in forum: Perl Misc
    Replies:
    10
    Views:
    177
    Sherm Pendley
    Aug 22, 2004
  5. Replies:
    7
    Views:
    301
    A. Sinan Unur
    Feb 14, 2006
Loading...

Share This Page