Home All Groups Group Topic Archive Search About

Simple composite control fires event fires first time but not second

Author
11 May 2009 3:59 PM
sellars.paul
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

Author
11 May 2009 11:55 PM
William Niver
<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!


<sellars.p***@googlemail.com> wrote in message
Show quoteHide quote
news:71d82764-f725-44de-a6f1-6c3980879b1c@o30g2000vbc.googlegroups.com...
> 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
>
Are all your drivers up to date? click for free checkup

Author
12 May 2009 8:54 AM
sellars.paul
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
Author
13 May 2009 3:19 PM
sellars.paul
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, sellars.p***@googlemail.com wrote:
Show quoteHide quote
> 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

Bookmark and Share