用户代码未处理 System.NullReferenceException
  Message="未将对象引用设置到对象的实例。"
  Source="App_Web_cy9uyixq"
  StackTrace:
       在 Default2.Page_Load(Object sender, EventArgs e) 位置 c:\Documents and Settings\wangzheng.BENG-ACB93E1E15\My Documents\Visual Studio 2005\WebSites\WebSite2\Default2.aspx.cs:行号 19
       在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       在 System.Web.UI.Control.OnLoad(EventArgs e)
       在 System.Web.UI.Control.LoadRecursive()
       在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
代码是这样的:button用来传递ckmc到另一个界面
  protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue.ToString().Trim() == "0")
        {
            Label1.Text = "<script>window.alert('请选择仓库名称!');</script>";
            DropDownList1.Focus();
        }
        else
        {
            Regex reg = new Regex("(^[1-9]{1}[0-9]{1,}\\.[0-9]{1,3}$)|(^[0-9]{1}\\.[0-9]{1,3}$)|(^[1-9]{1}[0-9]{1,}$)|(^[0-9]{1}$)");
            if (!reg.IsMatch(TextBox1.Text.ToString().Trim()))
            {
                Label1.Text = "<script>window.alert('起初仓库名称输入错误!');</script>";
                TextBox1.Focus();
            }
            else
            {
                string ckmc = DropDownList1.SelectedValue.ToString().Trim();
                Session["ckmc"] = ckmc;
                Response.Write(Server.UrlEncode("<script>self.parent.location.href='~/Default2.aspx';</script>"));
            }
        }
    }
界面二:
public partial class Default2 : System.Web.UI.Page
{
    static string ckmc;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ckmc = Session["ckmc"].ToString().Trim();
            TextBox1.Text = ckmc;
           }
    }
}其他的地方都是对的,为什么session传递不过去啊?在线等啊

解决方案 »

  1.   

    看起来没问题啊,要不换种方法吧,用QueryString试试
      

  2.   

    Response.Write(Server.UrlEncode(" <script>self.parent.location.href='~/Default2.aspx'; </script>")); 
    这种语句在客户端有用吗? 指的是这个 
    ~/
      

  3.   

    用这个试试string path = Response.ApplyAppPathModifier("Default2.aspx");
    Response.Write("<script>self.parent.location.href='"+path+"'; </script>");
      

  4.   

    你就没有传值过去啊,怎么可以或的呢
    试一下querystring吧
      

  5.   

    Response.Write("<script> self.location=\"Default2.aspx\";</script>");
      

  6.   

    滥用AJAX的结果......... 既然都跨页了,还用什么Callback啊...