asp标签不会以表单形式呈现

时间:2013-11-21 14:58:00

标签: html master-pages umbraco

我有一个包含申请表格的母版页,它上面有一组问题,然后在最后它应该有0到5个额外的问题,具体取决于申请的位置。以下是Apply.Masterpage文件中的代码段:

<div class="row">
      <label>Please specify the main 3 software languages / technologies you have worked with in the last 5 years, and at what level you would rate yourself (between 1 and 5 where 1 is poor and 5 is excellent) * 
              <asp:TextBox ID="QuestionC" runat="server" TextMode="MultiLine" Rows="10"></asp:TextBox>

              <asp:RequiredFieldValidator ID="QuestionCRequired" ControlToValidate="QuestionC"
              ErrorMessage="Please provide a mobile phone number." runat="server" />
      </label>
</div>

这很好,打印带有工作验证器和标签的文本框,但问题始于放在它下面的代码:

<% 
  string[] questions = new string[] { "question1", "question2", "question3", "question4", "question5" };
      foreach (var question in questions)
      {
          if(!(umbraco.library.GetItem(question).Equals("", StringComparison.Ordinal)))
          {
             var questionRequired = (question + "Required"); 
             %>
             <div class="row">
                <label><%:question%>+<%:umbraco.library.GetItem(question)%>
                      <asp:TextBox ID=<%:question%> runat="server" TextMode="MultiLine" Rows="10"></asp:TextBox>
                      <asp:RequiredFieldValidator ID=<%:questionRequired%> ControlToValidate=<%:question%>
                      ErrorMessage="Please anwer the question" runat="server" />
                 </label>
             </div>
         <%}
      }%>

应该打印两个额外的文本框,但它打印出来:

question1+ksdgfjsdgfjsdg
question2+jugkjfkhfkhg

其中question1是Umbraco中字段的名称,而“ksdgfjsdgfjsdg”是实际问题,所以它从Umbraco中选择了正确的数据,但它似乎跳过了很奇怪的asp标签因为工作很好几行以上。唯一的区别是使用&lt; %%&gt;附加问题中的标签。如何显示文本框?我试图让代码负责在macroScript中打印其他问题,但我现在只能得到它。

1 个答案:

答案 0 :(得分:0)

我在这里完全错了,但我不确定你是否可以用这种方式动态创建asp.net文本框。这就是为什么它只是在标签标签后立即给你的物品。

我认为如果您想动态创建它们,您必须执行类似

的操作
myTextBox = new TextBox();
myTextBox.ID = "txtIDGoesHere";
PanelForMyTextBox.Controls.Add(myTextBox);

但我可能误解了这个问题。