页面加载禁用@应用 [英] Page Load disable @ in aplication

查看:52
本文介绍了页面加载禁用@应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以取消页面的页面加载事件或其他页面生命周期事件?

Is it possible to disbale a page load event of page or any othe page life cycle event?

推荐答案

这是不可能的.
您可以使用if else语句和隐藏字段来跳过在页面加载事件中编写的代码.就像如果您希望页面加载代码不适用于按钮单击,那么您需要这样做.
代码只是显示你的想法.
it is not possible.
you can skip the code written in page load event by using if else statement and hidden field. Like if you want that page load code did not work for button click then you need to do that.
Code just show u idea.
<script>
var skipLoad = function ()
{
document.getElementById('<%=hiddenfield1.ClientID %>').value = 1;
}

</script>


<asp:button id="button1" runat="server" onclientclick="skipLoad()" onclick="button_click" xmlns:asp="#unknown"></asp:button>

<asp:hiddenfield id="hiddenfield1" value="0" runat="server" />




服务器端页面加载事件.




server side page load event.

protected void Page_load (   )
{
if ( hiddenfield1.value < 1 )
{
//write your here.
}
}


1.如果您想一次执行在页面加载事件中编写的代码,
而不是在页面加载事件中写入
1.If u want to execute the code written in the page load event for one time
than write inside the page load event
if(!IsPostback)
{
 write your code.
}



这样,您可以第一次执行您的代码,然后它将不会执行代码.

2.如果答案是永远不要使用该事件.

3.如果您想按照自己的意愿执行页面加载事件,请
比取全局变量
喜欢:



In this way u can execute your code for 1st time and than it will not execute the code .

2.If the answer is never than don''t use that event.

3.If u want to execute the page load event on your wish
Than take a global variable
Like:

//Global variable to control the page load event.
Boolean blnVariable = false;

private void page_load()
{
  if(blnVariabel)
  {
      your code.
  }
}



并在要执行代码时将blnVariable设置为true.



and set the blnVariable to true when you want to execute the code.


这篇关于页面加载禁用@应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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