动态添加Html代码问题 如何在aspx页面中指定位置动态添加html代码知道respose.write()可以添加html代码,但是如何在指定的位置添加html代码请达人指点,非常感谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以用一 Literal 控件,它是可以放在任意地方的。设置它的文本为html代码就可 ClientScript.RegisterStartupScript()ClientScript.RegisterClientScriptBlock()不要用respose.write(),用ClientScript.RegisterStartupScript()具体参数,你可以根据提示 自己写写试试ClientScript.RegisterStartupScript()与ClientScript.RegisterClientScriptBlock()是有区别的,关于区别,我建议你自己用一下,看不出的时候 在去搜一下 就明白了 后台平凑html 放到一个字符串中a在前台 加<%字符串a%> 是这样<%=字符串%> 字符串的访问级别 要为protected 及以上 片段 例如 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%>这一可以说是动态添加吧 用Literal控件没有办法添加象下面这样的html代码<asp:Label ID='Label2' runat='server' Text='关键字' Width='65px'></asp:Label> Sandy945 说的极是 我忘记说了 其实就是PUBLIC 后台C#public void LoadAtomNodeInformation() { string html = string html = "<asp:Label ID='Label2' runat='server' Text='关键字' Width='65px'></asp:Label>";}前台<%=html%>结果页面返回CS0103: 当前上下文中不存在名称“html” 那如何动态添加控件,同时需要动态添加一些Ajax控件 那如何动态添加控件,同时还需要添加些Ajax控件 <%@ 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) { }} .aspx文件<div id=divhtml runat=server></div>.aspx.cs文件divhtml.InnerHtml="abc";用asp:Label也可以哦。 后台: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%> vs2005 web.config问题 我的分页怎么不好用啊 三层构架中,对于一般复杂的业务逻辑,需要多次访问数据库的,代码如何处理? div做的tab之间切换的问题???? 请问asp.net中,如何让一个应用程序或者dll文件,根据所给的URL生成相应的页面(类似google,baidu等) 问一下各位有经验的人,提供这样的服务有没有市场?谢谢 关于GridView字段绑定的问题. 在用CompareValidator进行验证时,ValueToCompare怎么用啊? easyUI DataGrid问题 我的session只对本页有效,愁死我,高分求助 一个问题 水晶报表的分组问题
ClientScript.RegisterStartupScript()
ClientScript.RegisterClientScriptBlock()不要用respose.write(),用ClientScript.RegisterStartupScript()
具体参数,你可以根据提示 自己写写试试
ClientScript.RegisterStartupScript()
与
ClientScript.RegisterClientScriptBlock()
是有区别的,关于区别,我建议你自己用一下,看不出的时候 在去搜一下 就明白了
是这样<%=字符串%> 字符串的访问级别 要为protected 及以上
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%>
这一可以说是动态添加吧
<asp:Label ID='Label2' runat='server' Text='关键字' Width='65px'></asp:Label>
其实就是PUBLIC
后台C#
public void LoadAtomNodeInformation()
{
string html = string html = "<asp:Label ID='Label2' runat='server' Text='关键字' Width='65px'></asp:Label>";
}前台
<%=html%>结果页面返回CS0103: 当前上下文中不存在名称“html”
那如何动态添加控件,同时需要动态添加一些Ajax控件
那如何动态添加控件,同时还需要添加些Ajax控件
<%@ 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)
{ }
}
<div id=divhtml runat=server></div>.aspx.cs文件
divhtml.InnerHtml="abc";用asp:Label也可以哦。
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%>