|
這里,我來通過一個Demo來說明這個應用。
需求:
1. 用戶在UI上輸入一個數值(比如:5),系統動態為用戶加載這個數值的Url Address輸入域;
2. 用戶輸入的Url Address內容需要通過Url格式驗證;
3. 用戶提交輸入內容后,系統給出提交的結果
設計如下:
1. Css樣式設置:
以下為引用的內容:
復制代碼 代碼如下:
<style type="text/css">
.item
{
margin:10px;
border-bottom:solid 1px #CCC;
}
.item2
{
margin:5px;
}
.input
{
width:200px;
}
</style>
2.前臺頁面代碼:
復制代碼 代碼如下:
<div>
<div class="item">
Please input a number:
<ASP:TextBox runat="server" CssClass="item" ID="txtTextCount"></ASP:TextBox>
<ASP:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtTextCount" ValidationGroup="CreateTextBox" Display="Dynamic"
ErrorMessage="Required to input content!"></ASP:RequiredFieldValidator>
<ASP:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtTextCount" ValidationGroup="CreateTextBox" Display="Dynamic"
runat="server" ErrorMessage="Only number is valid!" ValidationExpression="^/d+$"></ASP:RegularExpressionValidator>
<ASP:Button runat="server" ID="btnCreate" Text="Create TextBox List" ValidationGroup="CreateTextBox"
onclick="btnCreate_Click" />
<ASP:Button runat="server" ID="btnOK" Text="Get TextBox Content" ValidationGroup="ShowListContent"
onclick="btnOK_Click" />
</div>
<div runat="server" id="divControls" class="item"></div>
<div runat="server" id="divMessage">
</div>
</div>
2. 前臺頁面代碼:
以下為引用的內容:
復制代碼 代碼如下:
<div>
<div class="item">
Please input a number:
<ASP:TextBox runat="server" CssClass="item" ID="txtTextCount"></ASP:TextBox>
<ASP:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtTextCount" ValidationGroup="CreateTextBox" Display="Dynamic"
ErrorMessage="Required to input content!"></ASP:RequiredFieldValidator>
<ASP:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtTextCount" ValidationGroup="CreateTextBox" Display="Dynamic"
runat="server" ErrorMessage="Only number is valid!" ValidationExpression="^/d+$"></ASP:RegularExpressionValidator>
<ASP:Button runat="server" ID="btnCreate" Text="Create TextBox List" ValidationGroup="CreateTextBox"
onclick="btnCreate_Click" />
<ASP:Button runat="server" ID="btnOK" Text="Get TextBox Content" ValidationGroup="ShowListContent"
onclick="btnOK_Click" />
</div>
<div runat="server" id="divControls" class="item"></div>
<div runat="server" id="divMessage">
</div>
</div>
說明, 動態創建的TextBox們將裝載到divControls中。
AspNet技術:ASP.NET 動態寫入服務器端控件第1/2頁,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。