SharePoint2013 Custom Field Type: getElementById doesn't work when textbox's ClientIDMode set to AutoID

655 Views Asked by At

I created a Custom Field Type with one textbox and one button.

<asp:TextBox ID="TextField" runat="server" ReadOnly="true"  ClientIDMode="Static"/>
<asp:Button ID="TreeButton" Text="..." runat="server" onclientclick="HandlePopupResult();" />

on button click , I call a javascript function (HandlePopupResult) to set a resultValue to textbox .

function HandlePopupResult(resultValue) {
        document.getElementById('TextField').value = resultValue; }

If I set ClientIDMode of 'TextField' to static , this code worked, but when I set it to AutoID the HandlePopupResult function doesn't work .

I set ClientIDMode="AutoId" of TextField and used

document.getElementById('<%=TextField.ClientID%>').value = resultValue;

then I got UnhandebleException

Trying to browse NewForm of each lists that has one field as type of my custom field.

It is necessery that my TextField CleintIDMode be AutoId and I can set value of textfield
I would appreciate any advice.

1

There are 1 best solutions below

0
On

I searched a lot and finally found this sample

http://bernado-nguyen-hoan.com/2011/11/07/walkthrough-custom-field-type-for-uploading-and-displaying-images-in-sharepoint-2010-lists/

this sample solved my problem by new way of getting controls clientId .