Results 1 to 2 of 2

Thread: A bit stuck adding code to Buttons

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    10

    A bit stuck adding code to Buttons

    I'm writing a program which accessess function in a .dll which occasionally raises events. I'm Caputuring these events within my program and I want to display a prompt (much like a modal dialog box) so the user can ok/cancel it. I've donr the code which creates the Box , labels and buttons but what I can't seem to work out is how to attach code to the buttons I have created. Bascially all I want is when they click a button it sets a values to true or false. Because the button doesn't exist until runtime I cant add an event handler, is there a way to do this when I create the button?

    This function is in a code file and creates the button:

    Code:
     
            Dim wcButton As New Button
    
            wcButton.ID = Name
            wcButton.Text = defaultvalue
            wcButton.Style.Add("Position", "Relative")
            wcButton.Style.Add("Left", Left)
            wcButton.Style.Add("Top", Top)
            wcButton.Style.Add("Height", Height)
            wcButton.Style.Add("Width", Width)
            wcButton.Enabled = Enabled
            wcButton.Visible = Visible
            wcButton.ToolTip = Tooltip
    
            If (TabIndex <> 0) Then
    
                wcButton.TabIndex = TabIndex
    
            End If
    The event handler calls a function to create a Prompt which creates a GenericHTMLControl and add the buttons and Labels as WebControls. This generic Control is then added to the page.

    I'm not entirly sure if this is the correct approach for how to create Modal style dialogs so if anyone else has a good way to implement them in ASP.NET please tell me.

    Andrew Aitken

  2. #2
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375
    Hi, add an event handler to the button (Something like this)

    VB Code:
    1. Dim wcButton As New Button
    2.  
    3.         wcButton.ID = Name
    4.         wcButton.Text = defaultvalue
    5.         wcButton.Style.Add("Position", "Relative")
    6.         wcButton.Style.Add("Left", Left)
    7.         wcButton.Style.Add("Top", Top)
    8.         wcButton.Style.Add("Height", Height)
    9.         wcButton.Style.Add("Width", Width)
    10.         wcButton.Enabled = Enabled
    11.         wcButton.Visible = Visible
    12.         wcButton.ToolTip = Tooltip
    13.  
    14. AddHandler wcButton.Click, AddressOf My_Clicker
    15.  
    16. ' Add in a Javascript Yes/ No button
    17. wcButton.Attributes.Add("onclick", "return confirm('Are you sure you want to do something?');")
    18.  
    19. ' then click function
    20. Private Sub My_Clicker(sender As Object, e As EventArgs)
    21. Response.Write(Sender.ID & " Has been clicked")
    22. End Sub



    Cheers
    MarkusJ

Posting Permissions

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



Click Here to Expand Forum to Full Width