首先我编译了一个类库取名为:" temp.dll "裹面代码如下:
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Drawing;
using System.Web;
using System.Web.Security;
using System.Web.UI.WebControls;namespace temp
{
public class temp
{
protected TextBox tempName;
public void tempAction()
{
tempName.Text = "中华人民共和国";
}
}
}temp.aspx 页面代码如下:<%@ Page language="C#" Debug="true" %>
<%@Import NameSpace="temp"%>
<html>
<head>
<script language="C#" runat="server">
void page_load(object sender,EventArgs e)
{
temp a = new temp();
a .tempAction();
}
</script>
</head>
<body>
<form name="fom" id="fom" method="post" runat="server">
<asp:textBox ID="tempName" runat="server"/>
</form>
</body>
</html>当实例化执行时并未将 textBox控件的值初始化,而出现错误说:
"并未将对象参考设定为对象的执行个体",这是怎么回事呢?请问要用什么方法才能实现在类库裹面对.aspx页面的控件操作呢?就如上面简单的赋值操作,请各位指点....谢谢!~
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Drawing;
using System.Web;
using System.Web.Security;
using System.Web.UI.WebControls;namespace temp
{
public class temp
{
protected TextBox tempName;
public void tempAction()
{
tempName.Text = "中华人民共和国";
}
}
}temp.aspx 页面代码如下:<%@ Page language="C#" Debug="true" %>
<%@Import NameSpace="temp"%>
<html>
<head>
<script language="C#" runat="server">
void page_load(object sender,EventArgs e)
{
temp a = new temp();
a .tempAction();
}
</script>
</head>
<body>
<form name="fom" id="fom" method="post" runat="server">
<asp:textBox ID="tempName" runat="server"/>
</form>
</body>
</html>当实例化执行时并未将 textBox控件的值初始化,而出现错误说:
"并未将对象参考设定为对象的执行个体",这是怎么回事呢?请问要用什么方法才能实现在类库裹面对.aspx页面的控件操作呢?就如上面简单的赋值操作,请各位指点....谢谢!~
解决方案 »
- ···谁有nhibernate的分页完整实例
- mvc 传参(action提交的list<Model>在control中接受不到)
- ASP.net里javascript LPT前台打印
- 我的页面判断输出,错在哪
- 高手们快来,帮小弟注释一下这几句
- ASP.Net 连接SQL Server 2000 的问题
- 用asp.net和c#开发网站需要连接数据库多次吗?
- 【求助】大虾们都进来帮帮忙,下面代码在firefox中怎么写才能执行?
- 发布网站有一个错误,但提示0行0列错误,也没有显示具体哪行错误。我晕!!!!
- 怎样实现IE中“查看”菜单中文字大小的设置
- 急呀急呀!网站上传后出现错误
- 程序执行批处理文件的问题,请高手帮忙
public void tempAction(Page page)
{
tempName=(TextBox)Page.FindControl("tempName");
tempName.Text = "中华人民共和国";
}
然后再引用的时候a .tempAction(Page);
首先,你的aspx文件与那个temp.dll文件没有任何关系。
然后,如果是要代码隐藏,你的类必须直接或间接的继承于System.Web.UI.Page。并在页面上指定,这样,页面才会从你的类继承,并找到合适的受保护的字段把控件赋给它。