checkBox and client confirm

  • Thread starter Thread starter Guest
  • Start date Start date
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 ?
 
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.
 
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.
 
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)
 
Back
Top