J
Joe Finsterwald
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.)
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.)