“return false” error(loses efficacy) in onclick event in IE with NeatUpload

by Weijie JIN on

In one of our project, we use NeatUpload to upload file to servers. There is an issue that when you place a NeatUpload control on the page, and you have a control with “return false” in event onclick, the “return false” won’t stop the execution of the control. This issue happens in Internet Explorer.

For example, I have a LinkButton control on the page named lbDelete, and I want to user confirm before submit. Usually I write like this:

lbDelete.Attributes.Add("onclick"
, "return confirm('Are you sure to delete this picture from the gift picture library ?')");

But, if there’s a NeatUpload control on the page, whatever the choice the user selects, the “Delete” action will always be executed.

So I did a little trick on the link button’s onclick event:

if(document.all)
{
	if(!confirm('Are you sure to delete this picture from the gift picture library ?'))
	{
		if(this.href!='#aImageGallery')
		{
			//save the original href value, and point to an anchor
			this.setAttribute('href1',this.href);
			this.href='#aImageGallery';
		}
		return false;
	}
	else
	{
		if(this.getAttribute('href1'))
		{
			this.href=this.getAttribute('href1');
		}
	}
}
else
{
	return confirm('Are you sure to delete this picture from the gift picture library ?');
}

 

And the compressed one when you want to add the onclick in codebehind:

            lbDelete.Attributes.Add("onclick", "if(document.all){if(!confirm('Are you sure to delete this picture from the gift picture library ?')){ if(this.href!='#aImageGallery'){ this.setAttribute('href1',this.href); this.href='#aImageGallery';} return false;}else{ if(this.getAttribute('href1')){this.href=this.getAttribute('href1'); }}}else{ return confirm( 'Are you sure to delete this picture from the gift picture library ?');}");

Hope it helps someone having the same problem in NeatUpload control. :)

  • Grant Yang

    I met the same problem yesterday,your trick really work,thanks! But if I use ImageButton instead of LinkButton, how can I resolve it?

  • http://jinweijie.myopenid.com/ jinweijie

    I think it’s the same as LinkButton. Otherwise, you can insert an image in to the LinkButton to display like an ImageButton.

  • Grant Yang

    I happened to find this problem is no longer exists in Internet Explorer,Maybe it is fixed by the new patch of IE,because my IE is set to auto-update.

  • http://jinweijie.myopenid.com/ jinweijie

    That sounds nice. :)

  • http://jinweijie.myopenid.com/ jinweijie

    that sounds nice~!

Previous post:

Next post: