Saturday, March 31, 2012

Why is the Text property missing?

I'm sure that I'm missing something blindingly obvious here, but.....

Can anyone tell me why certain properties are missing while editing controls/setting their properties in the HTML pane of the ASPX file in the VS IDE? The most basic example would be the TextBox. A typical declaration would be something like this:

<asp:TextBox ID="txtTest" Runat=server></asp:TextBox
OK, so now I want to bind my textbox to something. The way I would normally go about doing this would be like this:

<asp:TextBox ID="txtTest" Runat=server Text='<%# SomePropertyOnMyForm %>' ></asp:TextBox
This is fine. BUT the Text property does not show up in the VS IDE while I'm in HTML pane of the ASPX. If I swtich to the Design pane of the ASPX and look at the property sheet for my TextBox, the Text property is there! This is not the only property that is "missing" while editing in the HTML pane of the ASPX file.

Has anyone else had this problem? Does anyone know what is going on and why? I've searched loads of forums for an answer and can't find anything on the subject!

Any replies gratefully received,

Steve Camsell
steve.camsell@dotnet.itags.org.mmgroup.co.ukIn the ASP.NET document model, the Text property renders as a child node of the asp:TextBox element, rather than an attribute.
i.e.:

<asp:TextBox ID="txtTest" Runat=server><%# SomePropertyOnMyForm %></asp:TextBox>

Hmmm... if I create a new blank page and add the following as you suggest:

<asp:TextBox ID="txtTest" Runat="server"> <%# myName %> </asp:TextBox
I get a compile time error : "TextBox cannot have child of type 'DesignerDataBoundLiteralControl'"

If however, I change it as follows:

<asp:TextBox ID="txtTest" Runat="server" Text='<%# myName %>'></asp:TextBox
It works perfectly.

0 comments:

Post a Comment