页面计数器 [英] Page counter
本文介绍了页面计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次页面刷新时如何递增页面计数器。
这是我的代码:
Hi,
How can I increment the page counter each time when the page gets refreshed.
Here's my code:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Uid"].ToString() != null)
{
UserId = Convert.ToInt64(Session["Uid"].ToString());
lblCount.Text = Convert.ToString(Convert.ToInt32(lblCount.Text) + 1);
}
if (Session["iDataHUBID"].ToString() != null)
{
iDataHUBID = Convert.ToInt64(Session["iDataHUBID"].ToString());
//lblCount.Text = Convert.ToString(Convert.ToInt32(lblCount.Text) + 1);
}
lblCount.Text = Convert.ToString(Convert.ToInt32(lblCount.Text) + 1);
if (!Page.IsPostBack)
{
txtCDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
BindRejectReasonType();
BindProofTypes();
ScriptManager1.SetFocus(txtCDate);
txtBarcode.Attributes["onchange"] = "javascript:return Barcodetest();";
txtCAFNo.Attributes["onchange"] = "javascript:return CAFtest();";
btnAccept.Attributes.Add("onclick", "javascript:return ValidateAccept();");
lblCount.Text = "0";
}
}
问候,
Raj
Regards,
Raj
推荐答案
如果页面令人耳目一新则意味着
Page.IsPostBack
条件将为假。
所以你把代码放在里面
If The page is refreshing then it means
Page.IsPostBack
condition will be false.
so put you code inside
if(!Page.IsPostBack)
{
int PageRefreshCounter = 0;
Session["Counter"] = PageRefreshCounter;
}
if(Page.IsPostBack)
{
Session["Counter"] = ((int)Session["Counter"])++;
}
检查样本并相应更改代码
Check the sample and change your code accordingly
Label1.Text = "1";
if (Session["counter"] != null)
{
Label1.Text = Session["counter"].ToString();
Label1.Text = (Convert.ToInt16(Label1.Text) + 1).ToString();
}
if (!Page.IsPostBack)
{
Session["counter"] = Label1.Text;
}
Label1.Text = Label1.Text;
这篇关于页面计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文