先贴代码
  void Page_Load(Object S, EventArgs E)
  {
     if (Session["phone"] == null)
{
  Response.Redirect("password.aspx");
}
System.DateTime currentTime=new System.DateTime(); 
  currentTime=System.DateTime.Now; 
   int ls_year=currentTime.Year ;
   int ls_month=currentTime.Month ;
如何将上面代码中的ls_month值 以?的形式传到下面的printbower.aspx?ls_month=ls_month里
  void select1_Click(object sender, System.EventArgs e)
   {
   Response.Redirect("printbower.aspx?ls_month=" + ls_month );
}

解决方案 »

  1.   

    int ls_month;
    void Page_Load(Object S, EventArgs E)
      {
         if (Session["phone"] == null)
    {
      Response.Redirect("password.aspx");
    }
    System.DateTime currentTime=new System.DateTime(); 
      currentTime=System.DateTime.Now; 
       int ls_year=currentTime.Year ;
       ls_month=currentTime.Month ;
      }void select1_Click(object sender, System.EventArgs e)
       {
       Response.Redirect("printbower.aspx?ls_month=" + ls_month );
       }
      

  2.   

    或者用ViewState来定义页面级变量
      

  3.   

    System.DateTime currentTime=new System.DateTime(); 
      currentTime=System.DateTime.Now; 
       int ls_year=currentTime.Year ;
       int ls_month=currentTime.Month ;
    我把这几行放到void Page_Load 上面去,却提示
    CS1519: 类、结构或接口成员声明中的标记“=”无效
    放加void Page_Load里,在上面加int ls_mont;传过去的值是0 我要的是 currentTime.Month的值,怎么办呀。
      

  4.   

    public partial class _Default : System.Web.UI.Page 
    {
        private int ls_month;
        protected void Page_Load(object sender, EventArgs e)
        {
            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            int ls_year = currentTime.Year;
            ls_month = currentTime.Month;
        }
        void select1_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("printbower.aspx?ls_month=" + ls_month);
        }}
      

  5.   

    CS1519: 类、结构或接口成员声明中的标记“class”无效
    按照lfl931223的方法报上面的错误
    我是放在 <script language="C#" runat=server></script>里的。
      

  6.   

    private static int ls_month;
      

  7.   

    public partial class classA : System.Web.UI.Page (盡量不用_Default吧)
      

  8.   

    建议lz使用接口+Server.Transfer来传值。
      

  9.   

    //不用全局变量void Page_Load(Object S, EventArgs E)
      {
         if (Session["phone"] == null)
    {
      Response.Redirect("password.aspx");
    }
    System.DateTime currentTime=new System.DateTime(); 
      currentTime=System.DateTime.Now; 
       int ls_year=currentTime.Year ;
       ViewState["ls_month"]=currentTime.Month ;
      }void select1_Click(object sender, System.EventArgs e)
       {
       Response.Redirect("printbower.aspx?ls_month=" +ViewState["ls_month"].ToString());
       }//用ViewState
      

  10.   

    用ViewState比较好,呵呵……可惜没有分可以给了,都散尽了。但是心里真的很感激大家。谢谢!