在Page_Load之前调用函数 [英] Calling a function before Page_Load

查看:82
本文介绍了在Page_Load之前调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调用函数A()的按钮

I have a button that calls function A()

当我单击它时,我希望按该顺序拨打电话:

When I click on it I want the calls to be made in that order:

A()
Page_Load()

现在它正在做

Page_Load()
A()

有没有解决的办法,还是只是设计使然,我对此无能为力?

Is there a way around that or is it just by design and there's nothing I can do about it?

推荐答案

最简单的方法是使用HTML提交按钮,并检查它是否在Page_Init的每个回发中都位于表单中.

The easiest way to do this would be to use a HTML Submit button and check to see if it is in the Form on every postback in Page_Init

public void Page_Init(object o, EventArgs e)
{
     if(!string.IsNullOrEmpty(Request.Form["MyButtonName"]))
     {
          A();
     }
}

在您的ASP.NET代码中:

And in your ASP.NET code:

<Button Type="Submit" Name="MyButtonName" Value="Press Here To Do Stuff Early!" />

我认为这会起作用.

这篇关于在Page_Load之前调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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