Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: HTML User Control (.ascx File) May Not Work as Expected in Netscape

View products that this article applies to.

This article was previously published under Q318101

↑ Back to the top


The Hypertext Markup Language (HTML) that Visual Studio .NET generates for user controls on Web forms may fail to interact as expected with JavaScript when you use Netscape to render the control. You may receive the following error message in Netscape:
Element has no content
The problem is not specific to user controls (.ascx files). This problem occurs with any naming container. For example, you may experience the same behavior in a page that uses a Repeater control with a TextBox in the Repeater item.

↑ Back to the top


This problem occurs because Netscape uses the name instead of the ID to identify form input elements in its document object model (DOM) representation. Because ASP.NET uses a colon to name form input elements in user controls on a Web control on a page, you cannot use certain JavaScript access syntaxes that retrieve data from form fields through the DOM.

↑ Back to the top


To resolve this problem, edit the script to use the following syntax:
After you change the script to use this syntax, the script works as expected on both Microsoft Internet Explorer and Netscape.

↑ Back to the top

More information

Steps to Reproduce the Behavior

  1. Create a user control (.ascx) that contains at least one text input control.
  2. Declare the control (in its code-behind class file) to implement the INamingContainer interface.
  3. Create an .aspx page, and then drag an instance of the user control onto that page.
  4. 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.
  5. 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.

↑ Back to the top

Keywords: KB318101, kbprb

↑ Back to the top

Article Info
Article ID : 318101
Revision : 11
Created on : 2/19/2007
Published on : 2/19/2007
Exists online : False
Views : 432