简体   繁体   English

在asp:textbox中使用代码块

[英]Using Code Blocks in asp:textbox

I'm pulling two dates from a database using SQL and saving those values to the session variables "blackoutbegin" and "blackoutend". 我正在使用SQL从数据库中提取两个日期,并将这些值保存到会话变量“ blackoutbegin”和“ blackoutend”。 I'm either running into the error of "Code blocks are not supported in this context" or "the server tag is not well formed" when playing around with this code. 我在处理此代码时遇到“在此上下文中不支持代码块”或“服务器标签格式不正确”的错误。

Any suggestions on how to incorporate these session variables into the text of an asp:TextBox? 关于如何将这些会话变量合并到asp:TextBox的文本中的任何建议?

Or alternate options? 还是其他选择?

<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>

This answer will help you. 这个答案将为您提供帮助。

or simple you can assign the text to the textbox in pageLoad event as follow: 或简单,您可以将text分配给pageLoad事件中的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() +".";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM