manhcodedao / jquery-watermark

Automatically exported from code.google.com/p/jquery-watermark
0 stars 0 forks source link

Watermark not cleared when changing a dropdown with AutoPostback enabled in an UpdatePanel in ASP.NET #82

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The watermark is not being cleared before the postback occurs when using IE 
(other browsers have native support so aren't affected)

1. Create an asp.net WebForms project (vs2010 .net3.5 in my case)
2. Add an update panel
3. Add a text input control within the UpdatePanel
4. Apply jquery.watermark to the text input control and set text for the 
watermark
5. Add a DropdownList next to the text input (within the UpdatePanel). Set it's 
AutoPostback property to true
6. Add a label control next to the DropdownList
7. On the Page_Load event in the codebehind file of the control set the label 
control's text property to the DropdownList's SelectedValue property
7. Load the page and change the dropdown value.

You would expect the label control to still be empty but it will contain the 
watermark text.

I also have the AjaxToolkit added a reference so you might need to add the 
ToolkitScriptManager to your page as well to reproduce.

What happens is the jquery.watermark form.submit code is undone by the ASP.NET 
AJAX form submit handling added by using the UpdatePanel or the AjaxToolkit. If 
the postback is triggered by a button or link then the "beforeunload" event is 
fired and "$.watermark.hideAll()" is called and everything is correct. However 
the change event of the Select html element (what the DropdownList control 
renders as) is not a unload type of event which means "$.watermark.hideAll()" 
won't be called in this case.

I am using jQuery 1.6.4, jQuery.watermark (3.1.3), ASP.Net 3.5 WebForms, 
AjaxToolkit (3.5.40512.2)

Workaround:
As this is part of a complex application I trigger a custom event when the 
Select onchange event is fired. I bind to this custom event and in the handler 
call "$.watermark.hideAll()".

Original issue reported on code.google.com by Keith.Ki...@gmail.com on 2 Mar 2012 at 4:10

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Also you cannot use 
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRe
questHandler) to fix this as the request post body has already been build (in 
javascript) before it is called

Original comment by Keith.Ki...@gmail.com on 2 Mar 2012 at 4:22

GoogleCodeExporter commented 8 years ago
I have attached a Visual Studio 2010 sample demonstrating the problem. This 
uses jQuery 1.7.1, jQuery.watermark (3.1.3), ASP.Net 4 WebForms. 

Original comment by Keith.Ki...@gmail.com on 3 Mar 2012 at 9:00

Attachments:

GoogleCodeExporter commented 8 years ago
Marked as "invalid", because it's a complex scenario that the plugin already 
has techniques to work around.  The documentation here already addresses these 
issues -- when you are putting the plugin into JavaScript-initiated postbacks, 
you will need to make calls yourself to turn on/off the watermarks, if the 
plugin cannot handle itself.

Original comment by t...@speednet.biz on 13 Aug 2012 at 2:18