本文介绍了我只想在表单加载时执行某些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在窗体加载时调用一个方法,该方法将使用值填充变量,我希望仅在页面首次加载时才调用它,而不是在单击按钮或页面刷新时才调用它,这可能是

预先感谢您

Hi

I''m calling a method on form load that will populate a variable with a value, I want it to be called only when the page loads the First time not when a button is clicked or the page refreshes is that possible

Thank u in advance

推荐答案

protected void Page_Load(object sender, EventArgs e)
{

  string quoteNo;

  if(!IsPostBack)
  {
     quoteNo = Convert.ToString(Session["QuoteNo"]);
     if(string.IsNullOrEmpty(quoteNo)){
       // generate quoteNo and put it in a session variable
       quoteNo = GenerateQuoteNo();
       Session["QuoteNo"] = quoteNo;
       // use your quoteNo
     }
  }
  else
  {
     quoteNo = Convert.ToString(Session["QuoteNo"]);
     // use your quoteNo
  }
}


if(!IsPostBack)
{
//code for very first load//
}
else
{
//not first load//
}



希望对您有所帮助:)



hope it helps :)


这篇关于我只想在表单加载时执行某些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:10
查看更多