如何在aspx页面中指定位置动态添加html代码知道respose.write()可以添加html代码,但是如何在指定的位置添加html代码
请达人指点,非常感谢!

解决方案 »

  1.   

    你可以用一 Literal 控件,它是可以放在任意地方的。设置它的文本为html代码就可
      

  2.   


    ClientScript.RegisterStartupScript()
    ClientScript.RegisterClientScriptBlock()不要用respose.write(),用ClientScript.RegisterStartupScript()
    具体参数,你可以根据提示 自己写写试试
    ClientScript.RegisterStartupScript()

    ClientScript.RegisterClientScriptBlock()
    是有区别的,关于区别,我建议你自己用一下,看不出的时候 在去搜一下 就明白了
      

  3.   

    后台平凑html 放到一个字符串中a在前台 加<%字符串a%>
      

  4.   


    是这样<%=字符串%> 字符串的访问级别 要为protected 及以上
      

  5.   

    片段  例如
     Menu1 += "<ul id='navigation'> <li onmouseover='displaySubMenu(this)' onmouseout='hideSubMenu(this)' >";Node = "<a href='#' >" + dr["ss"].ToString().Trim() + "</a> <ul id='SubMen'>";Menu1 += Node
    如此拼凑--
    最终形成的html代码在前台的设计源里面引用  <%=Menu1%>
    这一可以说是动态添加吧
      

  6.   

    用Literal控件没有办法添加象下面这样的html代码
    <asp:Label ID='Label2' runat='server' Text='关键字' Width='65px'></asp:Label>
      

  7.   

    Sandy945 说的极是  我忘记说了 
    其实就是PUBLIC  
      

  8.   


    后台C#
    public void LoadAtomNodeInformation() 
    {
      string html = string html = "<asp:Label ID='Label2' runat='server' Text='关键字' Width='65px'></asp:Label>";
    }前台
    <%=html%>结果页面返回CS0103: 当前上下文中不存在名称“html”
      

  9.   


    那如何动态添加控件,同时需要动态添加一些Ajax控件
      

  10.   


    那如何动态添加控件,同时还需要添加些Ajax控件
      

  11.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddControl.aspx.cs" Inherits="AddControl" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        </div>
        </form>
    </body>
    </html>
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class AddControl : System.Web.UI.Page
    {
        protected override void OnPreInit(EventArgs e)
        {
            Label lbl;
            for (int i = 0; i < 5; i++)
            {
                lbl = new Label();
                lbl.ID = "lbl" + i.ToString();
                lbl.Text = "我是动态添加的第" + i.ToString() + "个";
                Page.Controls.Add(lbl);
                Page.Controls.Add(new Panel());//控制样式的作用,没实际意义
            }    }
        protected void Page_Load(object sender, EventArgs e)
        {    }
    }
      

  12.   

    .aspx文件
    <div id=divhtml runat=server></div>.aspx.cs文件
    divhtml.InnerHtml="abc";用asp:Label也可以哦。
      

  13.   

    后台:
    public partial class _Default : System.Web.UI.Page 
    {
        private string ht = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            ht = "<table><tr><td>哈哈</tr></td></table>";
        }
        public string htmlstr
        {
            set { ht = value; }
            get { return ht;}
        }
    }
    前台:
        <%=htmlstr%>