Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Help with .Attributes["onclick"]=...

Help with .Attributes["onclick"]=...

Scheduled Pinned Locked Moved ASP.NET
helpjavascriptsysadminquestion
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dgap
    wrote on last edited by
    #1

    Hi all, I am having a bit of trouble and it would be great if someone can help me out... This is what I'm trying to do: I have a button which performs server side stuff but before it does I want a confirmation box which I add in the server side code as follows: private void btnButton_Click(object sender, System.EventArgs e) { // Step 1: Prompt user if document overwrite if (pButton.Visible==true) { btnUploadScript.Attributes["onclick"]= "javascript:return confirm('Are you sure you wish to overwrite the existing document?')"; } //Step 2: Otherwise do other stuff (assuming user clicked 'OK') ... But the problem is that the first time I enter that page as the user the javascript "onclick" method doesn't fire... but it does every other time after that! Any help would be greatly appreciated!

    D W 2 Replies Last reply
    0
    • D dgap

      Hi all, I am having a bit of trouble and it would be great if someone can help me out... This is what I'm trying to do: I have a button which performs server side stuff but before it does I want a confirmation box which I add in the server side code as follows: private void btnButton_Click(object sender, System.EventArgs e) { // Step 1: Prompt user if document overwrite if (pButton.Visible==true) { btnUploadScript.Attributes["onclick"]= "javascript:return confirm('Are you sure you wish to overwrite the existing document?')"; } //Step 2: Otherwise do other stuff (assuming user clicked 'OK') ... But the problem is that the first time I enter that page as the user the javascript "onclick" method doesn't fire... but it does every other time after that! Any help would be greatly appreciated!

      D Offline
      D Offline
      DavidNohejl
      wrote on last edited by
      #2

      hmm and can't it be because btnButton_Click is called after button is clicked first time? :) Try it at Page_Load handler. Never forget: "Stay kul and happy" (I.A.)
      David's thoughts / dnhsoftware.org / MyHTMLTidy

      1 Reply Last reply
      0
      • D dgap

        Hi all, I am having a bit of trouble and it would be great if someone can help me out... This is what I'm trying to do: I have a button which performs server side stuff but before it does I want a confirmation box which I add in the server side code as follows: private void btnButton_Click(object sender, System.EventArgs e) { // Step 1: Prompt user if document overwrite if (pButton.Visible==true) { btnUploadScript.Attributes["onclick"]= "javascript:return confirm('Are you sure you wish to overwrite the existing document?')"; } //Step 2: Otherwise do other stuff (assuming user clicked 'OK') ... But the problem is that the first time I enter that page as the user the javascript "onclick" method doesn't fire... but it does every other time after that! Any help would be greatly appreciated!

        W Offline
        W Offline
        Wyxlwiis
        wrote on last edited by
        #3

        put the line in Page_Load; otherwise the Button1.Attributes will first be assigned in the Button1_Click event, thus it will behave as it does now private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) Button1.Attributes["onclick"] = "javascript:return confirm('Are you sure you wish to overwrite the existing document?'); } Wyx :)

        K 1 Reply Last reply
        0
        • W Wyxlwiis

          put the line in Page_Load; otherwise the Button1.Attributes will first be assigned in the Button1_Click event, thus it will behave as it does now private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) Button1.Attributes["onclick"] = "javascript:return confirm('Are you sure you wish to overwrite the existing document?'); } Wyx :)

          K Offline
          K Offline
          Kas_Aspnet
          wrote on last edited by
          #4

          I agree with Wyxlwiis. If i am not wrong you have to add the attributes in the page load event. If u add in the button click event the attributes will be added only after Button's server click. Kas_Aspnet

          D 1 Reply Last reply
          0
          • K Kas_Aspnet

            I agree with Wyxlwiis. If i am not wrong you have to add the attributes in the page load event. If u add in the button click event the attributes will be added only after Button's server click. Kas_Aspnet

            D Offline
            D Offline
            dgap
            wrote on last edited by
            #5

            Guys, Thanks a bunch! I really appreciate it! just one more thing... I made a customized 'confirm' function and I cant seem to get it to work... here is the code: function customConfirm ( ) { if (document.getElementById("pButton").style.visibility == "visible") { window.confirm('Are you sure you wish to overwrite the existing document?'); return; } } it works if I don't use the IF statement... I want it to check if a (panel) control is visible or not... if it is then fire the event again... I REALLY appreciate for all the help from you guys

            M S K 3 Replies Last reply
            0
            • D dgap

              Guys, Thanks a bunch! I really appreciate it! just one more thing... I made a customized 'confirm' function and I cant seem to get it to work... here is the code: function customConfirm ( ) { if (document.getElementById("pButton").style.visibility == "visible") { window.confirm('Are you sure you wish to overwrite the existing document?'); return; } } it works if I don't use the IF statement... I want it to check if a (panel) control is visible or not... if it is then fire the event again... I REALLY appreciate for all the help from you guys

              M Offline
              M Offline
              MihirV
              wrote on last edited by
              #6

              hi try this function customConfirm ( ) { if (document.Form1.pButton.style.visibility == "visible") { window.confirm('Are you sure you wish to overwrite the existing document?'); return; } } Here Form1 is the name or id of the Form in the Page.. Mihir...

              1 Reply Last reply
              0
              • D dgap

                Guys, Thanks a bunch! I really appreciate it! just one more thing... I made a customized 'confirm' function and I cant seem to get it to work... here is the code: function customConfirm ( ) { if (document.getElementById("pButton").style.visibility == "visible") { window.confirm('Are you sure you wish to overwrite the existing document?'); return; } } it works if I don't use the IF statement... I want it to check if a (panel) control is visible or not... if it is then fire the event again... I REALLY appreciate for all the help from you guys

                S Offline
                S Offline
                Shawn_H
                wrote on last edited by
                #7

                try throwing up this right before the if statement and check to see what the value of pbutton.style.visibility really is...maybe its not equal to "visible" as you are expecting alert(document.getElementById("pButton").style.visibility ); Shawn

                W 1 Reply Last reply
                0
                • S Shawn_H

                  try throwing up this right before the if statement and check to see what the value of pbutton.style.visibility really is...maybe its not equal to "visible" as you are expecting alert(document.getElementById("pButton").style.visibility ); Shawn

                  W Offline
                  W Offline
                  Wyxlwiis
                  wrote on last edited by
                  #8

                  I agree because if you hide a control you properly don't want it to take up space in the page and therefore use the display = "none"

                  1 Reply Last reply
                  0
                  • D dgap

                    Guys, Thanks a bunch! I really appreciate it! just one more thing... I made a customized 'confirm' function and I cant seem to get it to work... here is the code: function customConfirm ( ) { if (document.getElementById("pButton").style.visibility == "visible") { window.confirm('Are you sure you wish to overwrite the existing document?'); return; } } it works if I don't use the IF statement... I want it to check if a (panel) control is visible or not... if it is then fire the event again... I REALLY appreciate for all the help from you guys

                    K Offline
                    K Offline
                    Kas_Aspnet
                    wrote on last edited by
                    #9

                    Check the value set to the visibility property by including an alert message before if statement. It will tell you the story. Kas_Aspnet

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups