I have a HTML input box in my ASPX page like below
<input id="txtID" runat="Server" type="text" />
Now I have some code written in C# codebehind which calculate a value and I want that value to be displayed in the above TextBox.
I have already tried
txtID.Value = Number.ToString();
and
HtmlGenericControl ct = new HtmlGenericControl();
ct.InnerHTML = Number.ToString();
txtID.Controls.Add(ct);
but both of the above does not seems to set the display text of the textbox.
Can anyone help me figure out as to how do I get it done.
I cannot use
<asp:TextBox />
EDIT (WITH CORRECT ANSWER):
The way I was originally trying to do was correct i.e.
txtID.Value = Number.ToString();
The culprit was Placeholder Plugin which was getting called and was erasing the values from the TextBox. Hope this will help a lot of people like me who get stuck at such silly places.
You can change value of control by injecting Javascript on PageLoad or PageInit. Just say
GetValueDummy()method is your method to calculate a value and you are using jQuery.You need to inject a javascript to page in Page.Load handler.
In this code, txt is id of your input.
If you are not using jQuery just replace value of script variable to
After some point your page will be fully rendered and ready to send to client. So you cant directly modify it from c#. You can read more about page life time here: http://msdn.microsoft.com/en-us/library/ms178472.aspx