How to dynamically generate HTML using C #
1. Don't use response. Write, since the output normally goes to the top of the file, use literal, for example:
<Head> <asp: literal id = "Courier" runat = "server"/> <Form runat = "Server
In code behind,
Protected literal failed;
Void page_load (Object sender, eventargs E)
{
Response. Text = "<title> Hello World </title> ";
}
2. Use server controls
<Form runat = "server" id = "form1">
<Asp: button id = "BTN" runat = "server" onclick = "getvalue" text = "Submit"/>
</Form>
<Script language = "C #" runat = "server">
Void page_load (Object sender, eventargs E)
{
Response. Text = "<title> Hello World </title> ";
Textbox T = new Textbox ();
T. ID = "ABC ";
Form1.controls. Add (t );
Htmlinputtext hit = new htmlinputtext ();
Hit. ID = "def ";
Form1.controls. Add (hit );
}
Void getvalue (Object sender, eventargs E)
{
Textbox t = (textbox) findcontrol ("ABC ");
Response. Write (T. Text );
Response. Write ("<br> ");
Htmlinputtext hit = (htmlinputtext) findcontrol ("def ");
Response. Write (hit. value );
}
</SCRIPT>
If you insist on using response. Write ("<input name = 'xxx'>"), then you have to use request. Form ["XXX"] to retrieve the value