Link to home
Start Free TrialLog in
Avatar of allday
allday

asked on

attributes onclick is not working

  Private Sub btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click
        Me.btn1.Attributes("onClick") = "javascript:return " & _
            "confirm('Are you sure you want to delete?'). " & ""
  End Sub
         
what im doing wrong here?

when the user clicks on the button i want to display the message
Avatar of tusharashah
tusharashah

seems like syntact problem with confirm. the "." after your confirm() can be casue of problem.. try following :

Me.btn1.Attributes("onClick") = "return confirm('Are you sure you want to delete?'); "
Hi,

try this

    btn1.Attributes.Add("onclick", "return confirm('Are you sure you want to delete?');")

ayha
ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of allday

ASKER

if you do not put inside the page_load then you have to click twice to get the message i guess first time when you click it will initilize and second time it fires

so the solution of blxml2 was correct :)
Avatar of allday

ASKER

oh shoot i forgot to ask

the main thing......

if the user click ok how should i know if the user click ok or cancel ?

and how to i trap that and run condition based on that?

if the user clicks ok, the postback occurs. If the user clicks cancel, the postback does not occur.

Private Sub btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click
 'do your stuff for deletion      
End Sub
Avatar of allday

ASKER

you saying its safe?

it safe to write delete commands without writing any condtional statements?

Private Sub btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click
 'do your stuff for deletion      

'it safe to write delete commands without writing any condtional statements?
End Sub
You asked this: "if the user click ok how should i know if the user click ok or cancel"

I responded: " if the user clicks ok, the postback occurs. If the user clicks cancel, the postback does not occur."

No one mentioned the word safe. Therefore, do not put words in my mouth. You can of course quote what I have stated.

To make it safe, you have to include the scenario where Javascript is disabled as well as checking to see if the page is valid (with all validations passed) plus with any added business logic.
Avatar of allday

ASKER

can you please look at this

 btnDelete.Attributes("onClick") = "javascript:return " & _
                "confirm('Are you sure you want to delete ID: '" _
                & Me.txtID.Text & "' from Master?')"

im getting stupid error message in javascript and the error is:

Error: Expected ')'