1

ASP.NET coding in VB.NET -- web application. I am asking a few questions about the "proper way" to set the OnClientClick phrase in the aspx button declaration.

Option 1: leading with 'javascript:' and surrounding the js in {...}

<asp:Button ID="btnDelete" runat="server" CausesValidation="False"  SkinID="cmdButton" style="margin-left: 2em;"
   CommandName="Delete" Text="Delete" 
   OnClientClick = "javascript:{(!confirm('Do you want to delete this record?'); return false;}"

Option 2: Not leading with 'javascript:' and NOT surrounding the js in {...}

<asp:Button ID="btnDelete" runat="server" CausesValidation="False"  SkinID="cmdButton" style="margin-left: 2em;"
   CommandName="Delete" Text="Delete" 
   OnClientClick="if (!confirm('Do you want to delete this record?')) return false;"

Both options appear to work properly in IE-10, but have not tried other browsers. So I am curious about the different phrases.

What about the leading of 'javascript:'? -- what affect does this have?

What about the surrounding of the js with {...} -- what affect does this have?

Your comments are welcome -- what is the best way to construct the phrase.

Any other syntax (or style) or suggestions will be welcome.

Thanks, in advance...John

1 Answer 1

1

OnClientClick renders into the standard HTML onclick attribute, so put whatever works with it.

I.e. - no javascript prefix required, no brackets required as well.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.