好吧,我从不用这个:
<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>对于最后一个,我可以在后面的代码中这样调用textbox:
username.Text = "blah blah"但是对于第一个,我不能用id来称呼它。有人能告诉我如何在后面的代码中调用第一个示例input type吗?
发布于 2015-06-01 21:04:41
<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="" />发布于 2015-06-01 21:27:32
将runat属性添加到input中,在后面的代码中可以使用输入id在代码后面设置输入属性。
例如:您有以下文本框:
<input type="text" id="txt1" runat="server" />您可以从后面的代码中设置文本值:
txt1.Value = "my value";https://stackoverflow.com/questions/30583186
复制相似问题