1

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?

M. Wiśnicki
  • 6,094
  • 3
  • 23
  • 28
Sushant Tayade
  • 122
  • 4
  • 17

3 Answers3

2

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"; 
Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • Change it to value – Mohit S Dec 23 '16 at 08:40
  • Hi @SushantTayade if this answer has solved your question please consider [accepting it](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Mohit S Dec 23 '16 at 09:26
0

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";
VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • This is working. But why simple is not working. I have used in other pages, same like I have posted and it is not showing any errors over there. – Sushant Tayade Dec 23 '16 at 08:40
  • I think you are confusing it with a `
    `. That has a `InnerHtml` property. An `input` does not.
    – VDWWD Dec 23 '16 at 08:49
  • I have used same code for accessing input values from my login.aspx page. Is it the thing that I can use it for accessing but not for populating? – Sushant Tayade Dec 23 '16 at 08:53
0

.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.

Community
  • 1
  • 1
hasnayn
  • 356
  • 4
  • 22