return confirm no longer working on ASP.net page
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.jscript.

Post a new message to this list...

CapCity
We have a few ASP.net apps where we needed confirmation dialogs with buttons
in datagrids. The code goes something like this (in the ItemDataBound event
for the grid):

strJavaScript = "javascript: return confirm('Any changes made to this
scenario cannot be reversed. Also, results to a changed scenario cannot be
viewed until the scenario is submitted again. Continue with edit of scenario
?');"
btnLink = CType(e.Item.FindControl("cmdSelect"), LinkButton)

btnLink.Attributes.Add("onClick", strJavaScript)

This has worked flawlessly until recently. Now, on my development machine,
the dialog will still appear, but no matter which button I click it goes
ahead as if I clicked "OK". The other developers do not have this issue, it
still works for them. This happens with apps that have been in production
for a while. A few weeks ago it worked fine from my machine, now it doesn't.

My guess is that it is my browser. It's IE 6.0.2800.1106 SP1. Several of the
"Q" updates have been pushed onto machine, but nothing that the other
machines don't have. Security settings in IE look kosher. It seems as if the
javascript is running because I see the dialog. It seems that the "return"
value is being ignored.

Anyone ever experience something like this? I've googled, but no luck. Maybe
not wording it correctly.

Thanks for any insight you can provide.

Reply to this message...
 
    
Vidar Petursson
Hi

Loose the javascript: bit
btn.Attributes.Add("onclick","return confirm('blah')");

--
Best Regards
Vidar Petursson
==============================
Microsoft Visual: Scripting MVP 2000-2004
http://www.icysoft.com/
http://www.deus-x.com/ Instant e-commerce
http://www.microsoft.com/technet/scriptcenter/
Playground: http://213.190.104.211/ ( IE 5.5+ only )

No matter where you go there you are
==============================
"CapCity" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
CapCity
"Vidar Petursson" <Click here to reveal e-mail address> wrote in
message news:%Click here to reveal e-mail address...
[Original message clipped]

Thanks for the response, but it made no difference. Still behaves the same
way.

When I view the source I can see the code in there for the onclick, so
that's being recognized.

[Original message clipped]

Reply to this message...
 
    
bruce barker
its a known IE bug. it fails cancel the postback based on the return value.
while there is no fix, there is a workaround.

allowPostbackScript = @"<script>
function allowPostback(v) {
if (!v && document.all) event.returnValue = false;
return v;
}
</script>
";

RegisterStartupScript("allowPostback",allowPostbackScript );

strJavaScript = "javascript: return allowPostback(confirm('Any changes made
to this
scenario cannot be reversed. Also, results to a changed scenario cannot be
viewed until the scenario is submitted again. Continue with edit of
scenario
?'));"

-- bruce (sqlwork.com)

"CapCity" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> We have a few ASP.net apps where we needed confirmation dialogs with
buttons
> in datagrids. The code goes something like this (in the ItemDataBound
event
[Original message clipped]

Reply to this message...
 
 
System.Web.UI.WebControls.LinkButton




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com