• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1032
  • Last Modified:

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
0
allday
Asked:
allday
1 Solution
 
tusharashahCommented:
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?'); "
0
 
ayha1999Commented:
Hi,

try this

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

ayha
0
 
b1xml2Commented:
set the value up in page load
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
      If Not IsPostBack Then
            btn1.Attributes("onclick") = "return confirm('Are you sure you want to delete?');"
      End If
End Sub
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
alldayAuthor Commented:
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 :)
0
 
alldayAuthor Commented:
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?

0
 
b1xml2Commented:
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
0
 
alldayAuthor Commented:
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
0
 
b1xml2Commented:
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.
0
 
alldayAuthor Commented:
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 ')'
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now