[英]Calling Input Types in Code Behind
好的,我從不使用這個:
<input type="text" name="username" id="username" tabindex="1" class="form-control" placeholder="Username" value="" />
我通常使用這個:
<asp:TextBox type="text" name="username" id="username" tabindex="1" class="form-control" placeholder="Username" runat="server"></asp:TextBox>
對於最后一個,我可以像在我后面的代碼中那樣調用文本框:
username.Text = "blah blah"
但是對於第一個,我無法通過id
調用它。 誰能告訴我如何在我的代碼后面調用第一個示例input type
?
<input type="text" name="username" id="username" t....
您不能在后面調用代碼的第一個原因是它不是服務器端控件。 您只能在代碼中調用那些控件,這些控件在后面被定義為具有runat
屬性的服務器端控件。
要在代碼后面調用第一個,請添加runat="server"
屬性,例如
<input type="text" name="username" runat="server" id="username" tabindex="1" class="form-control" placeholder="Username" value="" />
將runat
屬性添加到input
然后在后面的代碼中使用輸入id在后面的代碼中設置輸入屬性。
對於示例:您具有以下文本框:
<input type="text" id="txt1" runat="server" />
並且您可以從后面的代碼中設置文本值:
txt1.Value = "my value";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.