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.

BUG: Data Binding Expression in the Style Attribute Is Deleted When You Switch from Design View to Source View in HTML


View products that this article applies to.

Symptoms

When you use a data binding expression to assign values to the style attribute of an ASP.NET server control, the style attribute is deleted when you switch from Design view to Source view.

↑ Back to the top


Workaround

To work around this problem, assign the required values to the style attributes in the codebehind file instead of modifying the HTML code. To do this, follow these steps:
  1. Start Microsoft Visual Studio .NET.
  2. Use Microsoft Visual Basic .NET or Microsoft Visual C# .NET to create a new ASP.NET Web Application project. By default, WebForm1.aspx is created.
  3. Add a TextBox ASP.NET server control to WebForm1.aspx, and then name the control TextBox1.
  4. Add two Button ASP.NET server controls to WebForm1.aspx.
  5. Right-click WebForm1.aspx, and then click View Code.
  6. Add the following sample code in the button click events to display and hide TextBox1:

    Visual Basic .NET Sample Code
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          ' To hide the text box
          TextBox1.Style("Display") = "none"
       End Sub
    
       Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
          ' To display the text box
          TextBox1.Style("Display") = "block"
       End Sub
    Visual C# .NET Sample Code
     private void Button1_Click(object sender, System.EventArgs e)
          { // To hide the text box
             TextBox1.Style.Add("Display","none");      
          }
    
          private void Button2_Click(object sender, System.EventArgs e)
          { // To display the text box
             TextBox1.Style.Add("Display","block");      
          }
    Note You can also assign the values in the codebehind file to other style attributes.
  7. On the Debug menu, click Start to run the application.
  8. Click Button1.

    Notice that TextBox1 is hidden.
  9. Click Button2.

    Notice that TextBox1 is visible.

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

Steps to Reproduce the Behavior

  1. Start Visual Studio .NET.
  2. Use Visual Basic .NET or Visual C# .NET to create a new ASP.NET Web Application project. By default, WebForm1.aspx is created.
  3. Add a TextBox ASP.NET server control to WebForm1.aspx.
  4. In Design view, right-click WebForm1.aspx, and then click View HTML Source.
  5. Add DISPLAY to the style attribute, and then set the attribute to the server variable as follows:
              <asp:TextBox id="TextBox1" style="DISPLAY :<%#  VisibleVariable%>; Z-INDEX :101; LEFT :338px; POSITION :absolute; TOP :130px" runat="server"></asp:TextBox>
    
    Note You can dynamically assign VisibleVariable to the DISPLAY attribute, to show or hide the text box.
  6. Right-click WebForm1.aspx, and then click View Code.
  7. Edit the code in the codebehind file. For example, add a comment line in the Page_Load event.
  8. Switch to Design view.
  9. In Design view, right-click WebForm1.aspx, and then click View HTML Source.

    Notice that the style attributes that are defined in server tags (<% %>) are deleted.

↑ Back to the top


References

For more information about data binding, visit the following Microsoft Web site: For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
316946� BUG: Visual Studio .NET Editor Malforms HTML Tags
305140� INFO: ASP.NET
302342� HOW TO: Add ASP.NET Server Controls to a Web Form and

↑ Back to the top


Keywords: kbpending, kbcontrol, kbproperties, kbide, kbdatabinding, kbhtml, kbwebforms, kbbug, kbstyle, KB822320

↑ Back to the top

Article Info
Article ID : 822320
Revision : 4
Created on : 5/23/2007
Published on : 5/23/2007
Exists online : False
Views : 370