简体   繁体   中英

check with javascript if textbox is empty while using ajaxcontroltoolkit TextBoxWatermark

I have an asp.net TextBox and I'm using the TextBoxWatermark of AjaxControlToolkit to have it display some hing text while the box is empty.

Problem is, onclient click of a certain button, I want to determine if the textbox is empty. The javascript code of

document.getElementById(fieldName).value == ""

Is not working, since the WaterMark extender with it's hint text making the code to think the field is not empty.

Any solution to this?

You can use the wrapper to access whether the watermark is being displayed or not with get_IsWaterMarked .

Sys.Extended.UI.TextBoxWrapper.get_Wrapper(document.getElementById(fieldName)).get_IsWatermarked()

I tried this with version 4.1.7.1213 of AjaxControlToolKit.

Got the code from looking at the source code of the TextBoxWatermark control. Refer to this: http://ajaxcontroltoolkit.codeplex.com/SourceControl/latest#Client/MicrosoftAjax.Extended/TextboxWatermark/TextboxWatermark.pre.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM