firing events

Discussion in 'ASP .Net' started by =?Utf-8?B?c2FyYQ==?=, Nov 28, 2004.

  1. hi all
    i need to fire a click events of a button that i add at run time what can i
    do??
    i need to get a property value of other controls that i add also at runtime
    i want to get this property when i click this button
    any ideas ??
    thanks
     
    =?Utf-8?B?c2FyYQ==?=, Nov 28, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?c2FyYQ==?=

    Kumar Reddi Guest

    You need to add an event handler to the click event of the Button, lets say
    your button's id is "Button1",

    Button1.Click +=new EventHandler(Button1_Click);

    where Button1_Click can be substitued with any other method you want, which
    has the same signature as the typical button click event handler has

    Good Luck

    "sara" <> wrote in message
    news:...
    > hi all
    > i need to fire a click events of a button that i add at run time what can

    i
    > do??
    > i need to get a property value of other controls that i add also at

    runtime
    > i want to get this property when i click this button
    > any ideas ??
    > thanks
     
    Kumar Reddi, Nov 28, 2004
    #2
    1. Advertising

  3. Hi Sara,

    You need to use AddHandler to create the event and Page.FindControl to get
    a reference to the control on the page.

    To fire an event, you just call it:
    http://msdn.microsoft.com/library/d...en-us/vblr7/html/vastmAddHandlerStatement.asp

    Some sample code below. Let us know if this helps?

    Ken
    Microsoft MVP [ASP.NET]


    Public btnOK As Button
    Public lblResult As Label
    Private Sub Page_Load _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    btnOK = New Button
    btnOK.ID = "btnOK"
    btnOK.Text = "OK"
    btnOK.ToolTip = "Click Me!"
    AddHandler btnOK.Click, AddressOf ClickHandler
    PlaceHolder1.Controls.Add(btnOK)

    lblResult = New Label
    lblResult.ID = "lblResult"
    PlaceHolder1.Controls.Add(lblResult)
    End Sub

    Private Sub ClickHandler _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs)
    Dim btnTemp As Button
    Dim lblTemp As Label
    lblTemp = Page.FindControl("lblResult")
    btnTemp = sender
    lblTemp.Text = btnTemp.ID
    End Sub


    <form id="Form1" method="post" runat="server">
    <asp:placeholder id="PlaceHolder1"
    runat="server"></asp:placeholder>
    </form>

    "sara" <> wrote in message
    news:...
    > hi all
    > i need to fire a click events of a button that i add at run time what can
    > i
    > do??
    > i need to get a property value of other controls that i add also at
    > runtime
    > i want to get this property when i click this button
    > any ideas ??
    > thanks
     
    Ken Cox [Microsoft MVP], Nov 28, 2004
    #3
    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. Dinesh Upare
    Replies:
    0
    Views:
    419
    Dinesh Upare
    Jul 16, 2003
  2. John
    Replies:
    0
    Views:
    313
  3. Guest

    Firing events?

    Guest, Oct 31, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    450
    Softwaremaker
    Nov 1, 2003
  4. SevDer
    Replies:
    2
    Views:
    1,319
    Walter Wang [MSFT]
    Nov 13, 2007
  5. Chris

    Events Events Events Please Help

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

Share This Page