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:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
With btn
.InnerText = "Apply"
.ID = "Button1"
'.Attributes.Add("runat", "server")
.Visible = True
End With
Me.Controls.Add(btn)
btn.Attributes.Add("OnClick", "javascript:if(confirm('Are you sure?') == false) return false;")
End Sub
Private Sub btn_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.ServerClick
Response.Write("OK")
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
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 ? :ehh: