发送页webform1.aspx:
<%@ Page Language="C#" %>
<script runat="server">    // Insert page code here
    //
      public string Name
    {
     get
     {
     return TextBox1.Text;
     }
    }
    
    public string EMail
    {
     get
     {
     return TextBox2.Text;
     }
    }
    
    void Button1_Click(object sender, EventArgs e) {
     Server.Transfer("anotherwebform.aspx");
    }</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
        </p>
        <p>
            <asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
        </p>
        <!-- Insert content here -->
    </form>
</body>
</html>
=======================================================
接收页anotherwebform.aspx:
<%@ Page Language="C#" %>
<script runat="server">    // Insert page code here
    //
    
    void Page_Load(object sender, EventArgs e) {
     webform1 w;
     w = (webform1)Context.Handler;
     Label1.Text=w.Name;
     Label2.Text=w.Email;
    }</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            <asp:Label id="Label1" runat="server">Label</asp:Label>
        </p>
        <p>
            <asp:Label id="Label2" runat="server">Label</asp:Label>
        </p>
        <!-- Insert content here -->
    </form>
</body>
</html>
编译错误,找不到类型或命名空间名称“webform1”(是否缺少 using 指令或程序集引用?)
请问如何解决?

解决方案 »

  1.   

    <%@ Page Language="C#" %>
    //*******************加如下
    <%@ Import Namespace="System.Web" %>
    <%@ Import Namespace="System.Web.UI.WebControls" %>
    //*****************************
    <script runat="server">
      

  2.   

    因为你在接收时,并没有为它做判断.
    Server.Transfer方式转过来的页面,有可能当前页面是转过来的页面,也有可能并不是转过来的页面,而是原来的页面.所以,在接收页面,你必须进一步判断.
    下面给出一个实际的例子,你自己参考一下,特别注意判断页面的名称与原页面的差别要传递值的页面asm_content_view.aspx
    /// <summary>
    /// 搜索值
    /// </summary>
    public string strText
    {
      get
      {
        return(this.txtsearch.Text);
      }
    }/// <summary>
    /// 搜索类型
    /// </summary>
    public string strType
    {
      get
      {
        return(this.listsearch.SelectedValue);
      }
    }/// <summary>
    /// 搜索
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void butsearch_Click(object sender, System.EventArgs e)
    {
      this.Server.Transfer("asm_content_list.aspx");
    }
    要接收的页面
    //查看有无从asm_content_view页面转来的搜索对象
    string strname = Context.Handler.ToString().ToLower();
    if( strname == "asp.asm_content_view_aspx")
    {
      mydata.content.page.asm_content_view myform = new asm_content_view();        
      myform = (mydata.content.page.asm_content_view)Context.Handler;
      this.txtsearch.Text = myform.strText;
      this.listsearch.SelectedValue = myform.strType;
    }
      

  3.   

    <%@ import namespace="system"%>
    <%@ import namespace="system.web.ui.webcontrols"%>
    <%@ import namespace="system.web"%>写得时候,要注意命名空间名称得大小写
      

  4.   

    用VS.NET里建个asp.net项目就可以了.. 为什么不用codebehind?
      

  5.   

    webform1 w;??
    这样不行吧
      

  6.   

    为 anotherwebform.aspx 执行子请求时出错。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
    =========================================
    哪位能发一个完整的aspx文件代码?我很急,谢谢
      

  7.   

    哪位能发一个完整的aspx文件代码?我很急,谢谢
    -----------
    我给你的那个,不就是完整的例子吗?还要再如何详细的?
    楼主要有尝试的勇气.
      

  8.   

    你那个没有包含html文件啊。我想要个,拿来就能运行的例子看一下。
      

  9.   

    html页面跟上述的代码基本没有关系.
    楼主这样的做法,太依赖他人,对你个人的进步很不好.
      

  10.   

    Server.Transfer("anotherwebform.aspx");
    没有声明引用的命名空间在页面上面加入
    <%@ Import Namespace="System.Web" %>
    <%@ Import Namespace="System.Web.UI.WebControls" %>即可
      

  11.   

    不是我太依赖别人,一来是急用,二来,我觉得不是cs代码的问题。我查了一本书了,好像要在html里面加<%@Reference page = "webform1.aspx"%>不知道是不是这样?