我只想在表单加载时执行某些操作 [英] I want to execute something only on form load

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

问题描述



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

预先感谢您

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
  }
}


尝试一下:

在页面的页面加载事件中.

Try this:

On the page load event of your page.

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



希望对您有所帮助:)



hope it helps :)


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆