post back event in server control

Discussion in 'ASP .Net Building Controls' started by Jon Paal, Sep 20, 2006.

  1. Jon   Paal

    Jon Paal Guest

    how do I get the button event recognized in the post back from a server control ??


    ========code=============

    Public Class MyButton
    Inherits System.Web.UI.Page
    Implements IPostBackEventHandler


    Public Response As HttpResponse = HttpContext.Current.Response


    ' Defines the Click event.
    '-----------------------------
    Public Event Click As EventHandler

    ' OnClick dispatches the event to delegates that
    ' are registered with the Click event.
    ' Controls that derive from MyButton can handle the
    ' Click event by overriding OnClick
    ' instead of attaching a delegate. The event data
    ' is passed as an argument to this method.
    '-----------------------------------------------
    Protected Overridable Sub OnClick(e As EventArgs)
    RaiseEvent Click(Me, e)
    End Sub

    ' Method of IPostBackEventHandler that raises change events.
    '-----------------------------------------------------------
    Public Sub RaisePostBackEvent(eventArgument As String)
    Implements PostBackEventHandler.RaisePostBackEvent
    OnClick(EventArgs.Empty)
    System.Web.UI.Page.ClientScript.RegisterStartupScript(Me.GetType(), "MyScript", _
    "function AlertHello() { alert('Hello'); }", True)
    End Sub 'RaisePostBackEvent

    Public Sub New()
    Response.Write("<INPUT TYPE = submit name = " & Me.UniqueID & " Value = 'Click Me' />")
    End Sub


    End Class
    Jon Paal, Sep 20, 2006
    #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. Umut Tezduyar
    Replies:
    1
    Views:
    400
    Steven Cheng[MSFT]
    Oct 6, 2004
  2. The Crow
    Replies:
    4
    Views:
    5,903
    ProgTalk
    Jan 31, 2008
  3. Reshma Prabhu
    Replies:
    0
    Views:
    345
    Reshma Prabhu
    Oct 1, 2006
  4. =?Utf-8?B?Z29yaWxsYQ==?=
    Replies:
    1
    Views:
    766
    Masudur
    May 25, 2007
  5. Jon   Paal

    2nd attempt - post back event in server control

    Jon Paal, Sep 24, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    114
    Jon Paal
    Sep 24, 2006
Loading...

Share This Page