用C#动态生成HTML的问题

1. don't use response.write, since the output normally goes to the top of the file, use Literal, for example:


<head><asp:Literal server
in code behind,

protected Literal lit;

void Page_Load(Object sender, EventArgs e)
{
  lit.Text = "<title>hello world</title>";
}

2. use server controls

<form runat="server" >

<asp:Button />
</form>

<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
  lit.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

相关文章:

  • 2022-12-23
  • 2021-11-07
  • 2021-06-17
  • 2021-05-30
  • 2021-06-08
  • 2021-07-19
猜你喜欢
  • 2021-12-29
  • 2021-11-30
  • 2021-06-02
  • 2021-09-27
相关资源
相似解决方案