Simple composite control fires event fires first time but not second

S

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

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
 
W

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!
 
S

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
 
S

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,044
Messages
2,570,388
Members
47,052
Latest member
ketan

Latest Threads

Top