我在一个页面的代码文件里定义了一个类的静态成员变量 然后放在page_load里每次加一,页面没刷新一次结构却加了2
public class XXX
{
static int num;
private void Page_Load()
{
num++;
显示num; 结果每次都显示加了2 刷新后显示1 3 5 7
}
............
}
放在构造函数里也是这个结构
是不是 页面没刷新一次,类要重新生成2次啊
public class XXX
{
static int num;
private void Page_Load()
{
num++;
显示num; 结果每次都显示加了2 刷新后显示1 3 5 7
}
............
}
放在构造函数里也是这个结构
是不是 页面没刷新一次,类要重新生成2次啊
解决方案 »
- asp.net dropdownlist控件的问题
- 如何将aspx映射成html ????谢谢~~~
- 请问怎样在.net里获取 “上一条新闻”和“下一条新闻”
- 简单SQL语句,哪儿错了??????
- 各位高手,帮小妹看看这是怎么了?急!
- 怎么在asp.net的窗体中加以各树形的结构或有没有树形控件?
- 大数据量下datagrid导入到excel并下载到客户端
- 不关闭子窗口传值(多次传值)
- 水晶报表问题,在线等待
- 为何我照quickstart抄了一个datagrid1.aspx程序,第一次运行正确,可第二次运行却报错?
- 如何让一个页面在运行时变成像弹出窗口那样儿只有BODY,注意不是说那种用一个按纽点击出来的!
- 请问高手微软的这个三级菜单是怎么做的啊?
{
protected System.Web.UI.WebControls.Label NumberLabel; static int num;
private void Page_Load(object sender, System.EventArgs e)
{
num++;
NumberLabel.Text = num.ToString();
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
继续关注
void page_load()
{
num=num+1;
Label1.Text=num.ToString();
}
skytear(铁匠) 你是怎么测试的
继续关注
再问一下 我页面上有个datagrid 代码里有读取数据 排序 和分页代码 但是 应该没有运行啊
我在page_load里已经将绑定datagrid数据的代码注释了
怎么会刷新呢 ?????
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient ;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration ;namespace TRS.chips
{
/// <summary>
/// ShopTroubleContents 的摘要说明。
/// </summary>
public class ShopMainWin : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgShop;
protected System.Web.UI.HtmlControls.HtmlForm Form2;
protected System.Web.UI.WebControls.Button RetrunReport;
protected System.Web.UI.WebControls.Label Label4;
static string mySelect;
protected System.Web.UI.WebControls.Label Label1;
int num=0;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
num=num+1;
//Label1.Text=num.ToString();
Response.Write (num.ToString());
//return ;
/*if(!IsPostBack)
{
HttpCookie cookie = Request.Cookies ["MyFirstCookie"];
//判断是否已经登录
if ((null== cookie.Values["IsShop"])&&(null== cookie.Values["IsServer"]))
{
this.ShowAlertMsg("没有发现指定的cookie,请重新登录!");
}
//门店登录
if ( (cookie.Values["IsShop"]=="1")&&( cookie.Values["IsServer"]=="0"))
{
mySelect="select ReportCode,TroubleTitle,TroubleStateName,ReportDate,LiabilityPersonName,TroubleLiabilityPersonName,TroubleStateID from vw_TroubleReport_TroubleState where ShopCode='"+cookie.Values["ShopCode"]+"' and TroubleStateID BETWEEN 1 and 4 order by ReportDate desc " ;
dgShopLoginBind();
ShopGetBackColor("等待评价");
}
}*/
} private void dgShopLoginBind() //门店人员登录时DataGrid中显示的信息
{
String dsn = ConfigurationSettings.AppSettings["TRS"];
SqlConnection myConnection = new SqlConnection(dsn);
myConnection.Open();
HttpCookie cookie = Request.Cookies ["MyFirstCookie"];
//获得故障上报的门店ID和未被归档的记录
//把记录写入DataSet ds中
SqlDataAdapter da=new SqlDataAdapter(mySelect,myConnection);
DataSet ds=new DataSet();
da.Fill(ds,"temp");
// ds.Tables["temp"].DefaultView.Sort=SortField;
// dgShop.DataSource=ds.Tables["temp"].DefaultView;
dgShop.DataSource=ds.Tables["temp"];
dgShop.DataBind();
da.Dispose();
myConnection.Close();
}
//如果上报表单的状态未4(等待评价),门店登陆时,此行记录显示未不同的颜色
private void ShopGetBackColor(string TroubleState)
{
// String dsn = ConfigurationSettings.AppSettings["TRS"];
// SqlConnection MyConn = new SqlConnection(dsn);
int i; for(i=0;i<dgShop.Items.Count;i++)
{
if(dgShop.Items[i].Cells[5].Text==TroubleState)
{
dgShop.Items[i].BackColor=System.Drawing.Color.Red;
}
}
}
private void dgShop_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgShop.CurrentPageIndex = e.NewPageIndex;
dgShopLoginBind();
ShopGetBackColor("等待评价"); }
public void ShowAlertMsg(string strMsg)
{
Page.RegisterStartupScript("key","<script language='javascript'>alert('" + strMsg + "');</script>");
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dgShop.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgShop_PageIndexChanged);
this.dgShop.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dgShop_SortCommand);
this.dgShop.SelectedIndexChanged += new System.EventHandler(this.dgShop_SelectedIndexChanged);
this.RetrunReport.Click += new System.EventHandler(this.RetrunReport_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void dgShop_SelectedIndexChanged(object sender, System.EventArgs e)
{
} private void RetrunReport_Click(object sender, System.EventArgs e)
{
Response.Redirect("TroubleReport.aspx");
} private void dgShop_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
HttpCookie cookie = Request.Cookies ["MyFirstCookie"];
switch((string)e.SortExpression) //通过SortExpression来确定(DataView)dv的排序方式
{
case "ReportCode":
mySelect="select ReportCode,TroubleTitle,TroubleStateName,ReportDate,LiabilityPersonName,TroubleLiabilityPersonName,TroubleStateID from vw_TroubleReport_TroubleState where ShopCode='"+cookie.Values["ShopCode"]+"' and TroubleStateID BETWEEN 1 and 4 order by ReportCode desc " ;
dgShopLoginBind() ;
break;
case "TroubleTitle":
mySelect=...;
dgShopLoginBind() ;
break;
case "ReportDate":
mySelect=...;
dgShopLoginBind() ;
break;
case "LiabilityPersonName":
mySelect=... ;
dgShopLoginBind() ;
break;
case "TroubleLiabilityPersonName":
mySelect=... ;
dgShopLoginBind() ;
break;
case "TroubleStateName":
mySelect=...;
dgShopLoginBind() ;
break;
}
// SortField=e.SortExpression;
// dgShopLoginBind(); }我得Page_Lode()却是执行了2次,但是我把里面的全都注释掉了 怎么会还是执行2次呢。继续关注