BUG: Data Binding Expression in the Style Attribute Is Deleted When You Switch from Design View to Source View in HTML (822320)
The information in this article applies to:
- Microsoft ASP.NET (included with the .NET Framework 1.1)
- Microsoft ASP.NET (included with the .NET Framework) 1.0
SYMPTOMSWhen 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.WORKAROUNDTo 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:
- Start Microsoft Visual Studio .NET.
- 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.
- Add a
TextBox ASP.NET server control to WebForm1.aspx, and then name the control TextBox1.
- Add
two Button ASP.NET server controls to WebForm1.aspx.
- Right-click WebForm1.aspx, and then click View
Code.
- 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. - On the Debug menu, click
Start to run the application.
- Click Button1.
Notice that
TextBox1 is hidden. - Click Button2.
Notice that
TextBox1 is visible.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
REFERENCESFor 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
302342 HOW TO: Add ASP.NET Server Controls to a Web Form and
Modification Type: | Major | Last Reviewed: | 8/8/2003 |
---|
Keywords: | kbpending kbControl kbstyle kbProperties kbide kbDataBinding kbhtml kbWebForms kbbug KB822320 kbAudDeveloper |
---|
|