簡體   English   中英

如何創建一個可以生成自己的字段和新面板的ASP.NET C#?

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

我正在嘗試創建一個網絡應用程序,可以像Google表單一樣創建調查表。

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

這是生成面板的C#代碼

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

但是當我單擊添加問題按鈕時,它不會添加面板

盡管我無法從代碼中分辨出問題所在,但問題可能出在問題參數上。 同時使用帶有控制器的MVC,它將更加干凈,並且VS會根據您的模型和控制器自動為您生成View,我認為從長遠來看,它將節省您的時間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM