简体   繁体   中英

Calling Input Types in Code Behind

OK, I never use this :

<input type="text" name="username" id="username" tabindex="1" class="form-control" placeholder="Username" value="" />

I usually use this :

<asp:TextBox type="text" name="username" id="username" tabindex="1" class="form-control" placeholder="Username" runat="server"></asp:TextBox>

With the last one I am able to call the textbox like so in my code behind :

username.Text = "blah blah"

But with the first one I am not able to call it by the id . Can anyone tell me how I can call the first example input type in my code behind?

<input type="text" name="username" id="username" t....

First one you can't call in code behind cause it's not a server side control. You can call only those control in your code behind which are defined as server side control with runat property.

To call the first one in your code behind add the runat="server" property like

<input type="text" name="username" runat="server" id="username" tabindex="1" class="form-control" placeholder="Username" value="" />

Add the runat property to the input and in the code behind you can set input properties in the code behind with input id.

For Eample : you have this textbox:

<input type="text" id="txt1" runat="server" />

and You Can Set text value from code behind:

txt1.Value = "my value";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM