Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

OnClientClick in an asp:LinkButton - using confirm() doesn't work in     every browser

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dddan - 14 Dec 2007 18:52 GMT
Here's my code:

<asp:LinkButton
   OnClick="DeleteFile"
   OnClientClick="if (!confirm ('Are you certain you want to delete
this file?') ) return false;"
   runat="server"
   ID="DeleteButton">DELETE
</asp:LinkButton>

Now, this works fine in FireFox but in IE7 on Vista it deletes the
file whether the user hits OK or Cancel.  Any guidance/ideas?

Thanks!
bruce barker - 14 Dec 2007 19:12 GMT
there is a long standing IE bug (since 5.5) where returning false doesn't
cancel the event as it should.

function cancelEvent()
{
  // ie hack
  if (window.event) window.event.cancelBubble = true;
  return false;
}

<asp:LinkButton
    OnClick="DeleteFile"
    OnClientClick="if (!confirm ('Are you certain you want to delete
this file?') ) return  cancelEvent();"
    runat="server"
    ID="DeleteButton">DELETE
</asp:LinkButton>

-- bruce (sqlwork.com)

> Here's my code:
>
[quoted text clipped - 10 lines]
>
> Thanks!
David C - 14 Dec 2007 20:16 GMT
I use this kind of thing very often and have never had a problem with IE6 or
IE7.  The only difference is I create a separate confirmdel() Javascript
function and use something like this.

   function confirmdel(deltype)
   {
       if (window.confirm('Are you sure you want to delete this ' + deltype
+ '?') == false)
       {
           return false;
       }
   }

On the LinkButton I use OnClientClick="return confirmdel('file');"

HTH
David

> there is a long standing IE bug (since 5.5) where returning false doesn't
> cancel the event as it should.
[quoted text clipped - 30 lines]
>>
>> Thanks!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.