Steps to Reproduce the Behavior
- Create a user control (.ascx) that contains at least one text input control.
- Declare the control (in its code-behind class file) to implement the INamingContainer interface.
- Create an .aspx page, and then drag an instance of the user control onto that page.
- In the containing page, include some JavaScript that tries to access values of the <INPUT> tag. This code fails with the error message that is listed in the "Symptoms" section.
- Render the resulting .aspx page in Netscape 4.73, and then review the HTML code. Notice that the ASP.NET naming convention for controls appears as follows:
INPUT ID="UserControlID:ControlID" NAME="UserControlID:ControlID"
If you change the
targetSchema property of both the user control and the .aspx page to Internet Explorer 3.02/Navigator 3, the control is persisted as:
input name="UserControlID:TextBox1" type="text" id="UserControlID_TextBox1"
You always receive the "Element has no content" error if all of the following conditions are true:
- You add a TextBox control (TextBox1) to an instance of a user control with ID "UserControlID" in a form named formName.
- You use client-side JavaScript to access the value that the user types in the TextBox1 text box.
- You try to use the following simple dotted DOM syntax to access through the ID of the TextBox (UserControlID_TextBox1) when you view the page in Netscape:
myval = document.formName.UserControlID_TextBox1.value;
The error always occurs in this scenario because JavaScript under Netscape uses the
Name attribute of the
TextBox to identify the
TextBox in the DOM. The ASP.NET naming convention causes the
Name attribute to be rendered with a colon (for example, UserControlID:TextBox1). However, in JavaScript, you cannot reference the name that is assigned to the
TextBox in the simple dotted DOM syntax. Therefore, you must use the explicit form of addressing instead. For example:
myval = 'document.formName["UserControlID:TextBox1"].value';
With this revised syntax, the JavaScript works as expected on both Microsoft Internet Explorer and Netscape.
The third-party products that are discussed in this article are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products.