[英]Load html and asp server controls via an external javascript file
我正在嘗試通過外部javascript文件動態加載表格(html和asp服務器控件)。 html控件加載沒有問題。 但是ASP服務器控件沒有顯示...如何獲取服務器控件以在其位置顯示其外觀...?
謝謝
外部javascript文件:
function BuildPage()
{
var html = "";
html += "<table width='500px' cellspacing='10'>";
html += "<tr><td align='center' colspan='2'><h3>Employee Input Form</h3><hr></td></tr>";
html += "<tr><td>First Name:</td>";
html += "<td><asp:TextBox ID='tbFName' runat='server'></asp:TextBox></td></tr>";
html += "<tr><td>Last Name:</td>";
html += "<td><asp:TextBox ID='tbLName' runat='server'></asp:TextBox></td></tr>";
html += "<tr><td>Address1:</td>";
html += "<td><asp:TextBox ID='tbAddr1' runat='server'></asp:TextBox></td></tr>";
html += "<tr><td>Address2:</td>";
html += "<td><asp:TextBox ID='tbAddr2' runat='server'></asp:TextBox></td></tr>";
html += "<tr><td>City:</td>";
html += "<td><asp:TextBox ID='tbCity' runat='server'></asp:TextBox></td></tr>";
html += "<tr><td>State:</td>";
html += "<td><asp:TextBox ID='tbState' runat='server'></asp:TextBox></td></tr>";
html += "<tr><td>Zip Code:</td>";
html += "<td><asp:TextBox ID='tbZipCode' runat='server'></asp:TextBox></td></tr>";
html += "<tr><td>Contry:</td>";
html += "<td><asp:TextBox ID='tbCountry' runat='server></asp:TextBox></td></tr>";
html += "<tr><td colspan='2'><asp:Button ID='btnSave' runat='server' Text='Save' /></td>";
html += "<td><asp:Label ID='lblSaved' runat='server' Text=''></asp:Lavel></td></tr>";
html += "</table>";
return html;
}
Default.html:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<button type='button' onclick="document.write(BuildPage())">Click for Employee Form</button>
</asp:Content>
當你有一個
<asp:TextBox ID='tbZipCode' runat='server'></asp:TextBox>
在ASP.NET標記中,這意味着.NET框架將在服務器端注冊此控件,但是HTML中不存在此控件。
.NET Framework將該控件呈現為:
<input type="text" ID="tbZipCode" />
例如,您的TextBox的“ Text”屬性將呈現為HTML輸入控件的“ value”屬性。
因此,您無法使用Javascript創建服務器端控件,因為.NET Framework不會注冊它們,也不會呈現它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.