2
votes

I am working on SharePoint to create a Feedback questionnaire form using an application page that is basically a aspx page.

I wish to do this by emulating MVC as far as possible. I've set up my model in the code-behind:

public List<QuestionViewModel> modelQuestions = new List<QuestionViewModel>();

Next, I need to display each question and an appropriate input depending on the question type (e.g. single line, multi line, single selection, multiple selection).

I've got it displaying the questions correctly:

<fieldset class="what-went-wrong">
    <% for (int i = 0; i < modelQuestions.Count; i++) { %>
        <p>
            <label for="QuestionText">
                <% if (modelQuestions[i].Required) { %>
                <span class="req-field indicator">*</span>
                <% } %>
                    <%= modelQuestions[i].QuestionText %>
                <% if (modelQuestions[i].Required) { %>
                <span class="req-field right">* Required field</span>
                <% } %>
            </label>
        </p>
    <% } %>
</fieldset>

This give's me the question text. I'm now trying to construct the appropriate input, but this <% %> tags is not working for this:

<% if(modelQuestions[i].QuestionTypeId == QuestionType.SingleLine) { %>
    <input id="modelQuestions_<% i %>" name="modelQuestions[<% i %>]" type="text" placeholder="<% modelQuestions[i].Placeholder %>" />
<% } %>

I can't seem to get it to construct the html element using details from the model (in the value for id, name, placeholder etc.)

Also, I've no idea how to go about posting this back to the server when I get to that point.

Is there any merit in continuing? Are there other controls/methods more appropriate to use in this case with aspx?

1
Can you please remove personal story from the post?Alexei Levenkov
I would try to use an asp.net input instead of the html-input or working with a repeater. Have you considered building a custom control for your need? msdn.microsoft.com/en-us/library/ee231548.aspxNils

1 Answers

0
votes

You cannot generate HTML markup like this. Even data-binding expressions will not help, because they bind ASP.NET controls' attributes values, not the plain output HTML in the page.

You should generate the markup in the "code behind", like this:

Page markup:

<div id='AnswersPanel'>
<div>

Page code behind:

protected void PageLoad(...)
{
    AnswersPanel.InnerHtml = "";
    AnswersPanel.InnerHtml += string.Format("<input id='modelQuestions_{0}' name='modelQuestions[{0}]' type='text' placeholder='{1}' />",
                                                i.ToString(), 
                                              modelQuestions[i].Placeholder);
}