zoukankan      html  css  js  c++  java
  • 用C#动态生成HTML的问题

    用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 id="lit" runat="server" /></head>
    <form runat="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" 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)
    {
      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

  • 相关阅读:
    Explain 索引优化分析
    组合索引与前缀索引
    MySQL 索引的类型
    MySQL 字符集及校验规则
    MySQL 连接查询
    DQL 数据查询语言
    DML 数据操纵语言
    DCL 数据控制语言
    DDL 数据定义语言
    蓝桥杯大学B组省赛2020模拟赛(一)题解与总结
  • 原文地址:https://www.cnblogs.com/pingkeke/p/949930.html
Copyright © 2011-2022 走看看