Dr.*_*ail 10 asp.net webforms visual-studio
当我在我的.aspx应用程序中使用VisualStudio 2010中的自动完成时,关闭控件标记有不同的默认完成:
<asp:CheckBox />
<asp:Label></asp:Label>
Run Code Online (Sandbox Code Playgroud)
这种行为有解释吗?
<asp:CheckBox></asp:CheckBox>
<asp:Label />
Run Code Online (Sandbox Code Playgroud)
不会无效.
标签关闭就是这样
<asp:Label runat="server"></asp:Label>
Run Code Online (Sandbox Code Playgroud)
因为我们通常在两者之间打字
<asp:Label runat="server" ID="lblOne">better start programming now</asp:Label>
Run Code Online (Sandbox Code Playgroud)
复选框不是这种情况,我们在其中输入
<asp:CheckBox runat="server" Text="enable" ID="cbOne" />
Run Code Online (Sandbox Code Playgroud)
我们有两个元素的Text领域,为什么在一个我们更愿意写出来侧...看看这个例子中,标签或者其他类似的控制,我们可能不得不写的文字可能包括不允许的字符内文本属性,也许是一个复杂的CSS风格或者什么......从另一边的复选框只包含一个小文本(是的,不是,类似的东西)
<asp:Label ID="lblLabel" runat="server">
This is a <b>"label"</b>
<br />And one more line
</asp:Label>
and more example that compiles
<asp:Label ID="lblLabel" runat="server">
This is a <b>"label"</b>
<br />And one more line
<asp:Literal runat="server" ID="ltrOneMore">One more Control Inside</asp:Literal>
</asp:Label>
---but this is not compile--
<asp:Label ID="lblLabel2" runat="server"
Text="This is a <b>"label"</b>
<br /> and one more line"
/>
Run Code Online (Sandbox Code Playgroud)
在最后的结果是做出的决定 - 也许我们需要问他们真正的真正原因.
现在这也不是编译
<asp:CheckBox runat="server" ID="cbMyChbx">one<asp:CheckBox>
Run Code Online (Sandbox Code Playgroud)
复选框何时在页面上呈现是使用两个控件,一个输入和一个标签,因此他们可能需要帮助用户理解文本不在输入控件上.
这是因为ASP.NET的Label控件是用ParseChildrenAttribute修饰的,ParseChildren(false)而while CheckBox不是.
您可以支持与自定义控件相同的行为,例如,使用以下代码,如果在Web窗体编辑器中使用MyControl,Visual Studio将表现得像Label:
[ParseChildren(false)]
public class MyControl : WebControl
{
...
}
Run Code Online (Sandbox Code Playgroud)
<asp:CheckBox />
由于元素没有内容,因此您可以使用/>关闭标记,而不是使用单独的结束标记
<asp:Label></asp:Label> or <asp:Label />
Run Code Online (Sandbox Code Playgroud)
在Web窗体页面上显示静态文本,并允许您以编程方式对其进行操作.
了解有关Web服务器控制的更多信息
| 归档时间: |
|
| 查看次数: |
718 次 |
| 最近记录: |