複数行のテキスト ボックスの最大長を設定しようとしています。私が遭遇している障害は、ページの読み込み時に JavaScript で設定できないことです。これは、InsertItemTemplate にあるためです。ページの読み込み時に、レコードを追加して InsertItemTemplate が表示されるまで、javascript エラー (エラー: 未定義または null 参照のプロパティ 'maxLength' を設定できません) がスローされます。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript">
function onPageLoad() {
var txtAddNotes = document.getElementById("formViewNewItem_NotesTextBox");
txtAddNotes.maxLength = 200;
}
</script>
</head>
<body onload="onPageLoad()">
<asp:FormView ID="formViewNewItem" runat="server" DataKeyNames="ID"
DataSourceID="datasource1" OnDataBound="formViewNewItem_DataBound">
<InsertItemTemplate>
<asp:TextBox ID="NotesTextBox" runat="server" Text='<%# Bind("Notes") %>' TextMode="MultiLine" Rows="3" Width="350px" />
</InsertItemTemplate>
</asp:FormView>
</body>
</html>