Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在绑定标签文本之前向asp.net标签添加文本_Asp.net_Visual Studio 2012 - Fatal编程技术网

在绑定标签文本之前向asp.net标签添加文本

在绑定标签文本之前向asp.net标签添加文本,asp.net,visual-studio-2012,Asp.net,Visual Studio 2012,我以前看过,但我不记得在哪里(甚至vs2012): 我可以添加一些标签到标签(或文本框?) 因此,当我将“Hello World!”绑定到标签时,我可以获得标签输出:“欢迎,Hello World!” 我的标签看起来像: <asp:Label ID="lblMessage" runat="server" Text="" PrependedText="Welcome, "></asp:Label> 您可以编写自己的控件,该控件派生自Label,也可以使用参考资料中的文

我以前看过,但我不记得在哪里(甚至vs2012):


我可以添加一些标签到标签(或文本框?)

因此,当我将“Hello World!”绑定到标签时,我可以获得标签输出:“欢迎,Hello World!”

我的标签看起来像:

<asp:Label ID="lblMessage" runat="server" Text="" PrependedText="Welcome, "></asp:Label>

您可以编写自己的控件,该控件派生自Label,也可以使用参考资料中的文本或硬编码在前面放置另一个控件:

<asp:Label ID="lblPrepend" runat="server" Text="Welcome, " />
<asp:Label ID="lblMessage" runat="server" Text="" />

解决这个问题的几种方法

Welcome, <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>


欢迎

我的理论是,你可以在HTML中“内联”完成这项工作,因此设计师有能力做到这一点……这可能是最好的,不是理想的,但很好。原因是,我正在根据DB的逻辑格式化标签。我希望设计人员能够更改预先挂起的文本。第二个标签数据也来自DB。第一个答案不起作用,b/c即使LBL消息标记为visible=false,也会显示欢迎,因此它违背了我的特定目的/需要。第二个答案也不能满足我的需要,因为设计师无法编辑“欢迎”注释,任何人也不能在不重新编译的情况下更改它。哎哟。第三个看起来很像我需要的,但是不完整,逻辑应该是什么?需要帮助…@ransems如果这个问题没有回答你的问题,你为什么要把它标记为答案?两年后你为什么要来这里?
Welcome, <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
<asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>

lblMessage.Text="Welcome, Hello World!";
public class MySpecialLabel: Label
{
public string PrependedText {get;set;}

//logic here to handle combining the strings when Text is set.
}
<div class="WelcomeSection">
  Welcome, <asp:Label runat="server" id="lblMessage">
</div>