By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,111 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,111 IT Pros & Developers. It's quick & easy.

How To Create a JavaScript Confirm inside a Condition in ASP.NET

P: n/a
Recently I needed to add a confirm to a LinkButton that called a
JavaScript function on success, and did nothing on failure. I found
documentation on adding a confirm, but not on how to place a confirm
in a conditional. In any case, I've found the answer and I thought
I'd share.

In VB.NET (in the code behind in VS.NET)

Adding just a confirm...

Dim l As LinkButton
l.Attributes.Add("onclick", "return confirm('Delete this item?');")

Adding a confirm inside a conditional...

Dim m As LinkButton
m.Attributes.Add("onclick", "if (confirm('Approve this item?'))
yourFunction('yourArg') ; else return false ;")

In C# (in the code behind in VS.NET)

Adding just a confirm...

LinkButton l ;
l.Attributes.Add("onclick", "return confirm('Delete this item?');") ;

Adding a confirm inside a conditional...

LinkButton m ;
m.Attributes.Add("onclick", "if (confirm('Approve this item?'))
yourFunction('yourArg') ; else return false ;") ;

(the important thing is to return a boolean = false to prevent a page
reload.)
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.