I recently had a problem where an ASP:Button on a webform was initiating an
unwanted postback (I had onClientClick set to a function, and assumed that
would override the postback.). I solved this by adding ;return null; to the
onClientClick call, and it stopped the postback.
Now, there were 2 other aspx pages that I *thought* I'd need to change as
well. One of them was in fact doing the postback, and one of them was not,
for all intents and purposes the pages are exactly the same. My question
is, under what circumstances does a button decide to, or not to postback?
All the pages have autoeventwireup ="true" The only *non-cosmetic*
difference I can really find is:
Page 1. - The button is in an update panel, and post back occurs
Page 2. - The button is in an update panel, and NO post back occurs
Page 3. - The button is NOT in an update panel, and post back occurs
I solved my original problem, but I would like to understand what the
governing principles are regarding Postbacks, and when they occur. I
thought they always occur when the runat="server" attribute is set for a
button, unless onClientClick code exists. But apparently I am not correct?
unwanted postback (I had onClientClick set to a function, and assumed that
would override the postback.). I solved this by adding ;return null; to the
onClientClick call, and it stopped the postback.
Now, there were 2 other aspx pages that I *thought* I'd need to change as
well. One of them was in fact doing the postback, and one of them was not,
for all intents and purposes the pages are exactly the same. My question
is, under what circumstances does a button decide to, or not to postback?
All the pages have autoeventwireup ="true" The only *non-cosmetic*
difference I can really find is:
Page 1. - The button is in an update panel, and post back occurs
Page 2. - The button is in an update panel, and NO post back occurs
Page 3. - The button is NOT in an update panel, and post back occurs
I solved my original problem, but I would like to understand what the
governing principles are regarding Postbacks, and when they occur. I
thought they always occur when the runat="server" attribute is set for a
button, unless onClientClick code exists. But apparently I am not correct?