使用代码块在asp:文本框

本文关键字:文本 asp 代码 | 更新日期: 2023-09-27 18:13:10

我使用SQL从数据库中提取两个日期,并将这些值保存到会话变量"blackoutbegin"answers"blackoutend"。在使用此代码时,我遇到了"在此上下文中不支持代码块"或"服务器标记格式不佳"的错误。

关于如何将这些会话变量纳入asp:TextBox的文本有什么建议吗?

或替代选项?

<asp:TextBox runat="server" 
             multiline="true" 
             ID="txtIndex" 
             Height="75px" 
             MaxLength="2000" 
             Width="100%" 
             TextMode="MultiLine" 
             Text="(More text before this)is expected to begin on '<%# Session["blackoutbegin"] %>' and is expected to end the week of '<%# Session["blackoutend"] %>'."> 
</asp:TextBox>

使用代码块在asp:文本框

这个答案会对你有所帮助。

或者简单地,您可以在pageLoad事件中将text分配给textbox,如下所示:

protected void Page_Load(object sender, EventArgs e)
{
   txtIndex.Text="(More text before this)is expected to begin on "+ Session["blackoutbegin"].ToString() +" and is expected to end the week of "+ Session["blackoutend"].ToString() +".";
}