Newbie - Rendered controls not firing events - help please

Discussion in 'ASP .Net Building Controls' started by Paul, Dec 12, 2003.

  1. Paul

    Paul Guest

    Hello,
    I have 2 user written rendered controls. If I put them on
    a page one at a time they work OK. If i put them on the
    page at the same time neither of the events fire.
    Anybody help please?

    ---------------------------
    aspx page

    Public Class TestPage
    Inherits System.Web.UI.Page
    Protected WithEvents ST1 As CCControls.SearchTerm
    Protected WithEvents lblST2 As
    System.Web.UI.WebControls.Label
    Protected WithEvents ST2 As CCControls.SearchTerm2
    Protected WithEvents lblST1 As
    System.Web.UI.WebControls.Label


    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub
    InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web
    Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    End Sub

    Private Sub ST1_SearchRequired(ByVal sender As Object,
    ByVal e As System.EventArgs) Handles ST1.SearchRequired
    lblST1.Text = ST1.SearchString
    End Sub


    Private Sub ST2_SearchRequired2(ByVal sender As
    Object, ByVal e As System.EventArgs) Handles
    ST2.SearchRequired2
    lblST2.Text = ST2.SearchString
    End Sub
    End Class

    ---------------------
    control 1


    Imports System.ComponentModel
    Imports System.Web.UI

    <DefaultProperty("SearchString"), ToolboxData("<
    {0}:SearchTerm runat=server></{0}:SearchTerm>")> Public
    Class SearchTerm
    Inherits System.Web.UI.WebControls.WebControl
    Implements IPostBackDataHandler

    Private Const ImageHome As String
    = "/changecontrol/images/banners/home.jpg"

    Public Event SearchRequired As EventHandler

    Public Property SearchString() As String
    Get
    Return viewstate("SearchString")
    End Get

    Set(ByVal Value As String)
    viewstate("SearchString") = Value
    End Set
    End Property


    Protected Overrides Sub Render(ByVal output As
    System.Web.UI.HtmlTextWriter)
    output.AddAttribute(HtmlTextWriterAttribute.Name,
    UniqueID)
    output.AddAttribute(HtmlTextWriterAttribute.Value,
    SearchString)
    output.RenderBeginTag(HtmlTextWriterTag.Input)
    output.RenderEndTag()
    End Sub

    Public Function LoadPostData(ByVal postDataKey As
    String, ByVal postCollection As
    System.Collections.Specialized.NameValueCollection) As
    Boolean Implements
    System.Web.UI.IPostBackDataHandler.LoadPostData
    If SearchString <> postCollection(postDataKey) Then
    SearchString = postCollection(postDataKey)
    Return True
    End If
    Return False
    End Function

    Public Sub RaisePostDataChangedEvent() Implements
    System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEven
    t
    OnSearchRequired(EventArgs.Empty)
    End Sub

    Public Sub OnSearchRequired(ByVal e As EventArgs)
    RaiseEvent SearchRequired(Me, EventArgs.Empty)
    End Sub
    End Class


    -------------------------------
    control 2

    Imports System.ComponentModel
    Imports System.Web.UI

    <DefaultProperty("SearchString"), ToolboxData("<
    {0}:SearchTerm2 runat=server></{0}:SearchTerm2>")> Public
    Class SearchTerm2
    Inherits System.Web.UI.WebControls.WebControl
    Implements IPostBackDataHandler

    Public Event SearchRequired2 As EventHandler

    Public Property SearchString() As String
    Get
    Return viewstate("SearchString2")
    End Get

    Set(ByVal Value As String)
    viewstate("SearchString2") = Value
    End Set
    End Property

    Protected Overrides Sub Render(ByVal output As
    System.Web.UI.HtmlTextWriter)
    output.AddAttribute(HtmlTextWriterAttribute.Name,
    UniqueID)
    output.AddAttribute(HtmlTextWriterAttribute.Value,
    SearchString)
    output.RenderBeginTag(HtmlTextWriterTag.Input)
    output.RenderEndTag()
    End Sub

    Public Function LoadPostData(ByVal postDataKey As
    String, ByVal postCollection As
    System.Collections.Specialized.NameValueCollection) As
    Boolean Implements
    System.Web.UI.IPostBackDataHandler.LoadPostData

    If SearchString <> postCollection(postDataKey) Then
    SearchString = postCollection(postDataKey)
    Return True
    End If
    Return False

    End Function

    Public Sub RaisePostDataChangedEvent() Implements
    System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEven
    t
    OnSearchRequired2(EventArgs.Empty)

    End Sub

    Public Sub OnSearchRequired2(ByVal e As EventArgs)
    RaiseEvent SearchRequired2(Me, EventArgs.Empty)
    End Sub

    End Class
    Paul, Dec 12, 2003
    #1
    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?U2hvdXJpZQ==?=
    Replies:
    1
    Views:
    7,871
    =?Utf-8?B?U2hvdXJpZQ==?=
    Jan 21, 2004
  2. SevDer
    Replies:
    2
    Views:
    1,283
    Walter Wang [MSFT]
    Nov 13, 2007
  3. KJ
    Replies:
    0
    Views:
    117
  4. David Boike

    Child controls in Composite Controls not firing events

    David Boike, Aug 7, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    304
    David Boike
    Aug 7, 2003
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    334
    Chris
    Aug 30, 2005
Loading...

Share This Page