开发者

Ajaxtoolkit TextboxWatermarkExtender: How to change the text from Javascript

I think thaAjaxControlToolkitTextBoxWrapperThis use to work, but I think that upgrading to te latest version of teh Toolkit (4 something) broke it:

    var txtExpireYear = document.getElementById("ctl00_phPageContent_dtmPassportExpirationDate_txtYear");
  txtExpireYear.AjaxControlToolkitTextBox开发者_如何学GoWrapper.set_Value(dtmDateOfExpire.getFullYear()); 

I now get the error:

Microsoft JScript runtime error: 'AjaxControlToolkitTextBoxWrapper' is null or not an object

Executing this:

txtExpireYear.innerText="value1" txtExpireYear.value="value2"

results in the watermark text being changed, not the textbox's text.


The text of the textbox is handled by the behavior object of the TextBoxWatermarkExtender.

To access this object in javascript, first specify an ID for the behavior:

<asp:TextBox ID="myTextBox" ... />
<ajaxtoolkit:TextBoxWatermarkExtender ID="myTextBoxWatermark" BehaviorID="myTextBoxBehavior" TargetControlID="myTextBox"  WatermarkText="Enter data here ..." ... />

In javascript, find this object and use set_Text() method

$find('myTextBoxBehavior').set_Text('Entered Data');

Similar, there is a get_Text() method, to get the actual value of the textbox


Try this:

Change

txtExpireYear.AjaxControlToolkitTextBoxWrapper.set_Value(dtmDateOfExpire.getFullYear()); 

To this:

txtExpireYear.TextBoxWrapper.set_Value(dtmDateOfExpire.getFullYear())

If it doesn't work, swap the ScriptManager control you are using for the AjaxToolkit replacement control "ToolkitScriptManager"


If you want to change the text of the watermark itself, there is also a set_WatermarkText() method.

Expanding on Edwin's example:

$find('myTextBoxBehavior').set_WatermarkText('Entered Data'); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜