Question:
ASP.NET / Javascript issue?
instntpudn
2007-05-30 08:18:12 UTC
I have a asp.net checkbox. I need a javascript confirm popup. If accepted I need to execute the server function.

I add the attributes on page load as:
chkbox.Attributes.Add("onclick", "javascript:ConfirmDelete();")

The server function is:
CheckBox_CheckedChanged

it gets rendered as:
onclick="javascript:ConfirmDelete();setTimeout('__doPostBack(\'CheckBox1\',\'\')', 0)"

and finally the js is:
function ConfirmDelete()
{
if (confirm('Are you sure you want to delete this?'))
{
}
else
{
return false
}
}

it executes my js but then fails to proceed to the server side function. What the heck I am doing wrong? This shouldn't be as hard as I am making it...Thanks in advance!
Three answers:
Kamran
2007-05-30 08:59:53 UTC
CheckedChanged event is called before the Click event of the check box. Try reversing the calls i.e call js on CheckChanged event and click to call the server side event.



Other thing you can do is, add the js method ConfirmDelete on the checkChanged event. and change your js to to a postback, your ConfirmDelete method will look like



function ConfirmDelete()

{

if (confirm('Are you sure you want to delete this?'))

{

__doPostBack("<%= RadCombobox1.UniqueID %>","")



}

else

{

return false

}

}



don't add autopostback to your checkbox then. Give this a go and I am waiting to hear back
adamek
2016-12-12 11:23:21 UTC
hi 2 innovations for fixing up your subject. a million. you're able to acquire an improve to the javascript with the aid of going to procedures: Then upload-ons. Then interior the hot window click on the verify for updates interior the replace tab. 2. improve to the extra moderen version of Firefox the two uninstall and re set up. desire this facilitates Nighthawk
Riekkie
2007-05-30 08:28:06 UTC
The AutoPostBack property must be set to true for this control to do a postback


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...