C# 在asp:textbox中使用代码块

C# 在asp:textbox中使用代码块,c#,asp.net,textbox,codeblocks,C#,Asp.net,Textbox,Codeblocks,我使用SQL从数据库中提取两个日期,并将这些值保存到会话变量blackoutbegin和blackoutend中。我可能遇到这样的错误:在这个上下文中不支持代码块,或者在处理这个代码时服务器标记的格式不正确 关于如何将这些会话变量合并到asp:TextBox的文本中,有什么建议吗 还是其他选择 <asp:TextBox runat="server" multiline="true" ID="txtIndex"

我使用SQL从数据库中提取两个日期,并将这些值保存到会话变量blackoutbegin和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>
或者,您可以将文本分配给pageLoad事件中的文本框,如下所示:

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() +".";
}

这正是我需要的。非常感谢