Professional Web Applications Themes

post back event in server control - ASP.NET Building Controls

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) ...

  1. #1

    Default post back event in server control

    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.RegisterStartupScr ipt(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 Guest

  2. #2

    Default Re: post back event in server control

    > how do I get the button event recognized in the post back from a server
    > control ??
    Don't use 'Response.Write'.
    But use:

    override CreateChildControls()
    {

    base.CreateChildControls();

    Button btn = new Button;
    btn.Text = ...
    btn.Value = ...
    Controls.Add(btn);

    }


    --
    Happy Hacking,
    Gaurav Vaish | [url]http://www.mastergaurav.com[/url]
    [url]http://www.edujinionline.com[/url]
    [url]http://articles.edujinionline.com/webservices[/url]
    -------------------


    Gaurav Vaish \(www.EduJiniOnline.com\) Guest

Similar Threads

  1. Flash Player Post Back data to server
    By ShaftJL in forum Macromedia Flash Player
    Replies: 0
    Last Post: December 13th, 02:57 PM
  2. 2nd attempt - post back event in server control
    By Jon Paal in forum ASP.NET Building Controls
    Replies: 1
    Last Post: September 30th, 02:22 PM
  3. Dragging rows without a post back to the server.
    By Thomasa Gregg in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: July 2nd, 01:48 PM
  4. How to Capture Control Initaited the Post Back.
    By Lolam in forum ASP.NET General
    Replies: 1
    Last Post: July 31st, 07:08 AM
  5. Post back and control focus issues
    By Natty Gur in forum ASP.NET General
    Replies: 0
    Last Post: July 24th, 05:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139