如何避免在ASP.NET中加载2页 [英] How to avoid 2 page loads in ASP.NET

查看:61
本文介绍了如何避免在ASP.NET中加载2页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在我的网站上,我有一个按钮,当单击该按钮时,它将根据用户输入到多个已检查列表视图中的数据输入来构建查询字符串,并使用新的查询字符串重定向到同一页面.单击按钮时,首先执行页面加载,然后执行重定向的按钮单击事件,然后再次执行页面加载.我想避免发生两次回发.检查Page.IsPostBack 发生在页面加载内部,因此无法避免回发.请帮忙.

谢谢&

Hello all,

In my website, I have a button which when clicked builds a query string based on data input by the user into several checked list views and redirects to the same page with the new query string. On button click, the page load is executed first and then the button click event where redirection occurs and again a page load is executed. I want to avoid 2 postbacks from occuring. Checking Page.IsPostBack happens inside Page Load, so it cannot avoid a postback. Kindly help.

Thanks & regards.

推荐答案

在Page_Load事件中使用!Page.IsPostback.
代码如下所示:

Use !Page.IsPostback in Page_Load event.
The code is like that given below:

private void Page_Load()
{
    if (!Page.IsPostBack)
    {
        Validate();
    }
}


您无法避免两次回发,因为一个回发是从按钮单击事件中推送的,而另一个是从页面重定向事件中推送的.您在这里可以做什么?您可以检查Page.IsPostBack属性,并避免在页面加载时调用所有函数.
You cannot avoid two postbacks because one postback is pushed from the button click event and another from the Page redirection. What can you do here? You can check the Page.IsPostBack property,and can avoid calling all the functions on Page load.


这篇关于如何避免在ASP.NET中加载2页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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