checkBox and client confirm

G

Guest

I'm using asp.net 2.0

I have a checkbox with server checkedCanged event .
I must add a confirm on click event.
I have used this : myCheckBox.Attributes.Add("onClick", "return
CofirmFunction()"); on Page_Load event.

On page : <script type="text/javascript" language="javascript">
function CofirmFunction()
{
var test = confirm('message ?');
if (test) {return true;}
else {return false;}
}
</script>

The problem is that the myCheckBox_checkedCanged event don't work.

Can I solve the problem ?
 
R

Ray Booysen

enzo said:
I'm using asp.net 2.0

I have a checkbox with server checkedCanged event .
I must add a confirm on click event.
I have used this : myCheckBox.Attributes.Add("onClick", "return
CofirmFunction()"); on Page_Load event.

On page : <script type="text/javascript" language="javascript">
function CofirmFunction()
{
var test = confirm('message ?');
if (test) {return true;}
else {return false;}
}
</script>

The problem is that the myCheckBox_checkedCanged event don't work.

Can I solve the problem ?

You sure about the spelling?

CofirmFunction() not ConfirmFunction(). Just in case you've misspelt it
in one location.

Also, this can be shortened to:

function ConfirmFunction()
{
return confirm('message ?');
}


or even

myCheckBox.Attributes.Add("onclick", " return confirm('message ?');");

And make sure it only adds the attribute on the first page load and not
on postbacks.
 
G

Guest

thanks for reply,
You sure about the spelling?
Yes my source code is correct

the client confirm message works
Afetr confirm response (OK / Cancel)
also if I click on OK button, the server myCheckBox_checkedCanged event
don't work.
If I comment myCheckBox.Attributes.Add("onClick", "return
ConfirmFunction()");
the myCheckBox_checkedCanged work.
 
B

bruce barker \(sqlwork.com\)

if you view source, you will see your client onclick look something like:

onclick="return ConfirmFunction(); __doPostback('myCheckBox','')"

so you can see no matter what the function returns, the postback is not
done.

try:

myCheckBox.Attributes.Add("onClick",
"if (!ConfirmFunction()) return; else "
+ GetPostBackClientEvent(myCheckBox,"") + ";");

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top