我的show.dll的代码如下 using System;
using System.Web.UI;
namespace firstcontent
{
public class myshow:Control
{
protected override void Render(HtmlTextWriter writer)
{
writer.Write(" <textarea id=\"dcontent\" name=\"dcontent\" runat=\"server\" style=\"display:none\"> <div> </div> </textarea> <iframe id=\"my\" src=\"/Edit/index.htm?id=dcontent\" frameborder=\"0\" scrolling=\"no\" width=\"800px\" height=\"460px\"> </iframe>");
}
}
}
我的一个页面default.aspx引用了这个dll文件,具体代码如下 Default.aspx代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" Debug="true"%>
<%@Register TagPrefix="myfirstcontent" Namespace="firstcontent" Assembly="show"%>
<!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>
<myfirstcontent:myshow runat="server" />
</div>
</form>
</body>
</html> Default.aspx.cs代码如下 using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
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;
using System.Text.RegularExpressions; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.dcontent.Value = "sdaflafasdfsdf"; //我这里是对show.dll中的 id="dcontent"的textarea赋值,但出现的问题是,总是提示错误“_Default”不包含“dcontent”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“dcontent”(是否缺少 using 指令或程序集引用?)
}
} 请问,我如果想对dll中的textarea赋值,我已经对我的textarea进行了runat="server"啊,怎么不正确呢?请问该怎么做呢?
using System.Web.UI;
namespace firstcontent
{
public class myshow:Control
{
protected override void Render(HtmlTextWriter writer)
{
writer.Write(" <textarea id=\"dcontent\" name=\"dcontent\" runat=\"server\" style=\"display:none\"> <div> </div> </textarea> <iframe id=\"my\" src=\"/Edit/index.htm?id=dcontent\" frameborder=\"0\" scrolling=\"no\" width=\"800px\" height=\"460px\"> </iframe>");
}
}
}
我的一个页面default.aspx引用了这个dll文件,具体代码如下 Default.aspx代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" Debug="true"%>
<%@Register TagPrefix="myfirstcontent" Namespace="firstcontent" Assembly="show"%>
<!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>
<myfirstcontent:myshow runat="server" />
</div>
</form>
</body>
</html> Default.aspx.cs代码如下 using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
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;
using System.Text.RegularExpressions; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.dcontent.Value = "sdaflafasdfsdf"; //我这里是对show.dll中的 id="dcontent"的textarea赋值,但出现的问题是,总是提示错误“_Default”不包含“dcontent”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“dcontent”(是否缺少 using 指令或程序集引用?)
}
} 请问,我如果想对dll中的textarea赋值,我已经对我的textarea进行了runat="server"啊,怎么不正确呢?请问该怎么做呢?
所以你在Load方法中访问div,此时的div尚未生成。建议你看一下关于aspx页面加载的顺序,下文来自MSDN,希望能对你有所帮助
http://msdn.microsoft.com/zh-cn/library/aa479007.aspx#XSLTsection125121120120
{
Response.Write(GetControlHtml());
base.OnInit(e);
}