简体   繁体   中英

How create an ASP.NET C# that can generate its own field and and new panels?

I am trying to create a web app that can create a survey form just like google forms.

<asp:Panel ID="container" runat="server"></asp:Panel>
<asp:Panel ID="question" runat="server" Height="391px">
    <br />
    <br />
    <asp:Label ID="Label1" runat="server" Text="Question:  " Font-Size="Large"></asp:Label>
    <asp:TextBox ID="txtQuestion" runat="server" Font-Size="Large"></asp:TextBox>
    <asp:DropDownList ID="lstQuestionType" runat="server">
        <asp:ListItem Enabled="False" Selected="True">Question Type</asp:ListItem>
        <asp:ListItem>Short Answer</asp:ListItem>
        <asp:ListItem>Paragraph</asp:ListItem>
        <asp:ListItem>Multiple Choice</asp:ListItem>
        <asp:ListItem>Check Box</asp:ListItem>
        <asp:ListItem>Linear Scale</asp:ListItem>
    </asp:DropDownList>
    <asp:Button ID="btnGenerate" runat="server" OnClick="btnGenerate_Click" Text="Generate Question" Width="137px" />
</asp:Panel>

<asp:Button ID="btnAddQuestion" runat="server" Text="Add Question" OnClick="btnAddQuestion_Click" />

and this is the C# code that generates the panel

protected void btnAddQuestion_Click(object sender, EventArgs e)
{
    Panel newQuestions = new Panel();
    newQuestions = question;
    container.Controls.Add(newQuestions);
}

but when I click the add question button, it does not add the panel

Although i can't tell from the code probably the problem is with the question parameter. Also use MVC with controllers it will be much more clean and also VS automatically generates the View for you based on your models and controllers which i guess it will save you time in the long run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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