Load event behavior

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

    #1

    Load event behavior

    Hello,

    I just don't get it. I have a simple webform1.aspx page, when loaded
    for the first time, the load even fires which is fine.

    In webform1.aspx i have a button that has a onclick event, and in this
    event i do a response.redire ct to webform2.aspx page. However on the
    onclick event of the button, the Load event for webform1.aspx is
    loaded again! Then the redirection is done!

    And that's not all: once we are in webform2.aspx, if i do a
    response.redire ct to webform1.aspx, the load event in webform1.aspx
    fires twice!

    Could please someone explain me this weird behavior please? Thanks
  • Kevin Bilbee

    #2
    Re: Load event behavior

    Matt

    "Matt" <metal@rocks.co m> wrote in message
    news:md69hv8oiq k5f5brb8snm1des 78pvr5f4v@4ax.c om...[color=blue]
    > Hello,
    >
    > I just don't get it. I have a simple webform1.aspx page, when loaded
    > for the first time, the load even fires which is fine.
    >
    > In webform1.aspx i have a button that has a onclick event, and in this
    > event i do a response.redire ct to webform2.aspx page. However on the
    > onclick event of the button, the Load event for webform1.aspx is
    > loaded again! Then the redirection is done!
    >
    > And that's not all: once we are in webform2.aspx, if i do a
    > response.redire ct to webform1.aspx, the load event in webform1.aspx
    > fires twice!
    >
    > Could please someone explain me this weird behavior please? Thanks[/color]

    Use IsPostBack in the Load event to determine if it is a post back or not.
    Load will run every time the

    private void Page_Load(objec t sender, System.EventArg s e) {
    if (IsPostBack) {
    // This would be run if the page is posted back like in your situation
    // Do some code
    } else {
    // this would be executed the first time the page is loaded
    // do some other code
    }

    Kevin Bilbee


    Comment

    • Damian Maclennan

      #3
      Re: Load event behavior

      If you don't want the load event to fire why are you redirecting at all ?
      You could just go directly to webform2 via a hyperlink or some client side
      JS behind the button. That will save asp.net from having to fire up webform1
      when it isn't really needed.


      Damian




      "Matt" <metal@rocks.co m> wrote in message
      news:md69hv8oiq k5f5brb8snm1des 78pvr5f4v@4ax.c om...[color=blue]
      > Hello,
      >
      > I just don't get it. I have a simple webform1.aspx page, when loaded
      > for the first time, the load even fires which is fine.
      >
      > In webform1.aspx i have a button that has a onclick event, and in this
      > event i do a response.redire ct to webform2.aspx page. However on the
      > onclick event of the button, the Load event for webform1.aspx is
      > loaded again! Then the redirection is done!
      >
      > And that's not all: once we are in webform2.aspx, if i do a
      > response.redire ct to webform1.aspx, the load event in webform1.aspx
      > fires twice!
      >
      > Could please someone explain me this weird behavior please? Thanks[/color]


      Comment

      • Natty Gur

        #4
        Re: Load event behavior

        Hi,

        Could you send sample code ? I try to create this senario on machine
        without any luck.

        Natty Gur, CTO
        Dao2Com Ltd.
        28th Baruch Hirsch st. Bnei-Brak
        Israel , 51114

        Phone Numbers:
        Office: +972-(0)3-5786668
        Fax: +972-(0)3-5703475
        Mobile: +972-(0)58-888377

        Know the overall picture


        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        Working...