首先我编译了一个类库取名为:" 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页面的控件操作呢?就如上面简单的赋值操作,请各位指点....谢谢!~

解决方案 »

  1.   

    传当前页的参数进去可以实现,不过好像这样做没什么用嘛   
                 public void tempAction(Page page)
                    {
                           tempName=(TextBox)Page.FindControl("tempName");
                           tempName.Text = "中华人民共和国";
                    }
    然后再引用的时候a .tempAction(Page);
      

  2.   

    TextBox 等用户界面,必须在aspx文件中有对应的控件才能使用。建议楼主早点代码分离吧。
      

  3.   

    能告诉我这是为什么吗?为什么我上面的源代码不行呢???谢谢.....
    首先,你的aspx文件与那个temp.dll文件没有任何关系。
    然后,如果是要代码隐藏,你的类必须直接或间接的继承于System.Web.UI.Page。并在页面上指定,这样,页面才会从你的类继承,并找到合适的受保护的字段把控件赋给它。