Results 1 to 2 of 2

Thread: Javascript:Confirm button

  1. #1

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Javascript:Confirm button

    I've got a question: the following ASP.NET code works fully in my testproject. When I click my htmlbutton (defined protected withevents, not seeable in the code), I get a messagebox asking me what to do. Clicking yes fires the htmlbutton event, clicking no ignores it.

    This is the code:
    VB Code:
    1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         'Put user code to initialize the page here
    3.  
    4.         With btn
    5.             .InnerText = "Apply"
    6.             .ID = "Button1"
    7.             '.Attributes.Add("runat", "server")
    8.             .Visible = True
    9.         End With
    10.  
    11.         Me.Controls.Add(btn)
    12.         btn.Attributes.Add("OnClick", "javascript:if(confirm('Are you sure?') == false) return false;")
    13.     End Sub
    14.  
    15.     Private Sub btn_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.ServerClick
    16.         Response.Write("OK")
    17.     End Sub
    The problem is that I can't get it to work in my real project. The confirm message is shown, if I click cancel nothing happens, and if I click ok, something happens, but the underlying event is not fired.

    Could it be that the button is added to a placeholder control dynamically? Or that the button is placed within a table?

    Hope anyone could help, thanx in advance,

    JMvVliet

  2. #2
    Addicted Member rabid lemming's Avatar
    Join Date
    Feb 2005
    Posts
    210

    Cool Re: Javascript:Confirm button

    try this.... have a function in the head section of the page witch you can call at any time to do your prompt; then call the function from the button in the onclick event, see if that then works ?

    I will wait for death with a smile and a big stick

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