c# - Page_Load is called when leaving page -
i have master page , 2 web pages, webform1 , webform2. on master page there 2 linkbuttons in order go webform1 or webform2.
when click on linkbutton go webform1 page_load event handler webform1 called , page.ispostback == false. far good.
then when click go webform2 happens:
a) page_load event handler webform1 called again , page.ispostback == true. b) page_load event handler webform2 called , page_load == false. vice versa when going webform1.
why page_load webform1 called when i'm going webform2? loading webform2 , not webform1.
for pages: autoeventwireup="true".
<form id="form1" runat="server"> <div> <p>this mysite.master.</p> <p> <asp:linkbutton id="goto1" runat="server" onclick="goto1_click">go webform1</asp:linkbutton> </p> <p> <asp:linkbutton id="goto2" runat="server" onclick="goto2_click">go webform2</asp:linkbutton> </p> <asp:contentplaceholder id="contentplaceholder1" runat="server"> </asp:contentplaceholder> </div> </form> protected void goto1_click(object sender, eventargs e) { response.redirect("webform1.aspx"); } protected void goto2_click(object sender, eventargs e) { response.redirect("webform2.aspx"); } public partial class webform1 : system.web.ui.page { protected void page_load(object sender, eventargs e) { if (page.ispostback) { } } } public partial class webform2 : system.web.ui.page { protected void page_load(object sender, eventargs e) { if (page.ispostback) { } } }
to add on kirk's answer...
when want simple link page, don't use linkbutton
@ all. linkbutton
submit button, designed link - it's hooked magically through javascript asp.net builds automatically.
if want link send page, in regular html:
<a href="webform2.aspx">go webform2</a>
Comments
Post a Comment