If I have a standard HTML textbox: I can retrieve the value using Request.Form.
But how do I go about populating this textbox from the server-side? I tried
Request.Form["txtTest"] = "blah";
but got a readonly error.
If I have a standard HTML textbox: I can retrieve the value using Request.Form.
But how do I go about populating this textbox from the server-side? I tried
Request.Form["txtTest"] = "blah";
but got a readonly error.
If you want to have first class support for accessing the control by its id on the server side (as per .net controls) you would need to make it so it has a runat="server" tag.
Otherwise you can set the value dynamicaly by having a property in your code behind and pulling in the value from this on the aspx page using databinding e.g.
<input type=text value="<%=PropertyInCodeBehindClass %>" />
and
public string PropertyInCodeBehindClass
{
get;
set;
}
Remember that at the point when your server code runs, the client side textbox doesn't exist. The html page hosting the control was already submitted to the server as new request, and the web browser is expecting you to respond with a completely new page. Until that response arrives the browser will leave the page displayed, but that's just a convenient shell. The DOM that held your textbox is gone, and you haven't created a new one yet. You can't directly change your response by updating a property in the request.
This means you need to use the server-side representation of the control. If it's a server control, you might try txtTest.Text = "blah";
Otherwise, you need to the find where you generate that input tag and alter things appropriately.
Always two there are; no more, no less. A request and a response.