Help with .Attributes["onclick"]=...
-
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!
-
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!
hmm and can't it be because
btnButton_Click
is called after button is clicked first time? :) Try it atPage_Load
handler. Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy -
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!
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 :)
-
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 :)
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
-
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
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
-
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
-
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
-
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
-
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
Check the value set to the visibility property by including an alert message before if statement. It will tell you the story. Kas_Aspnet