Reputation: 132
I have written a code for textbox element in Sample.aspx file as follows:
<input id="Text1" type="text" runat="server"/>
This auto-generated the code in Sample.aspx.designer.cs
protected global::System.Web.UI.HtmlControls.HtmlInputText Text1;
Then to populate it's html from code-behind I have written this code:
Text1.InnerHtml = "Sample text";
This is giving me an error
HtmlInputText does not contain a definition for InnerHtml
What is the problem. Why it's giving me an error?
Upvotes: 2
Views: 3520
Reputation: 356
.Value
should work. Please check if there are any placeholder issue in your page. You can see the link for the similar type problem. In the link there are also an alternative way to set value into the input using JQuery/Javascript.
Upvotes: 0
Reputation: 35524
Why not use the asp.net TextBox Control? You have more options that way
<asp:TextBox ID="Text1" runat="server"></asp:TextBox>
Text1.Text = "Sample text";
Upvotes: 0
Reputation: 14064
Use the .Value
property to programmatically determine the text entered by the user into the text box. You can also use this property to provide default text for the text box.
Text1.Value = "Sample text";
Upvotes: 3