The difference between OnLoad and Page_Load is that OnLoad is just a overriden virtual method that corresponds to the "Load" event; the Page_Load is the wired up event handler. So, a "Load" event generates a call to OnLoad, which is turn generates calls to the "Load" event handlers (of which Page_Load is one).... if look at the docs you'll see that there are On* methods for each of the lifecycle events of the Page/Controls (so there's an OnInit, OnLoad, etc...).
The reason you aren't seeing the message is that you might be using Page_Load with the AutoEventWireup set to true. Here's the same code using the Page_Load handler, maybe you'll have an easier time with that.
Scott
<%@ Page language="c#" AutoEventWireup="true" Trace="true" %>
<script language="C#" runat="server">
public void Page_Load(object sender, EventArgs e)
{
this.Trace.Warn("OnLoad = " + this.Request["Btn1"]);
}
public void Btn1_Click(object sender, System.EventArgs e)
{
this.Trace.Warn("Hey");
}
</script>
<html>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="Btn1" runat="server" Text="Button" onclick="Btn1_Click"></asp:Button>
</form>
</body>
</html>
"Andreas Klemt" <> wrote in message news:ubfw0%...
Hello Scott,
thank you for your answer and code.
I have now a question: For what do I use override OnLoad() and what
is the difference to Page_Load() ?
I tested also your code but when I load the page or hit the button, I never
get to see the ("OnLoad = " + this.Request["Btn1"]) in my trace.
Thanks in advance for your answer.
Kind Regards,
Andreas
"Scott G." <> schrieb im Newsbeitrag news:...
Assuming that you know the button ID; the you can do something like this.Request["Btn1"] (i.e. look at the variables in the Request); if you don't necessarily know the button ID, I guess you could iterate over the Request values and look for the control and see what type of control is it.
Scott
<%@ Page language="c#" AutoEventWireup="false" Trace="true" %>
<script language="C#" runat="server">
protected override void OnLoad(EventArgs e)
{
this.Trace.Warn("OnLoad = " + this.Request["Btn1"]);
base.OnLoad(e);
}
public void Btn1_Click(object sender, System.EventArgs e)
{
this.Trace.Warn("Hey");
}
</script>
<html>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="Btn1" runat="server" Text="Button" onclick="Btn1_Click"></asp:Button>
</form>
</body>
</html>
"Andreas Klemt" <> wrote in message news:...
Hello,
how can I find out in Page_Load which button event is fired?
Thanks for any help in advance!!
Andreas
|