views:

264

answers:

2

Hi,

I have a .net 2.0 application and I can't work out why a button's onclick method is run on page refresh.

The exact scenario when this happens is a checkbox is ticked against each item the button is clicked and the onclick mthod processes this item, and the checkbox is cleared. Now when the page is refreshed for some reason the onclick method of the button is entered in to!

Any help much appreciated.

Thanks alot,

A: 

Check the default Checked property of the check box. You may be setting it "Checked" on onload. Will be able to help you more if you post the code.

Shoban
A: 

Thanks Shoban,

The problem was that the checkbox was checked within the form and when the page was refreshed this caused a postback.

I solved this by putting the below line of code at the end of the button click method: Response.Redirect(Request.Url.PathAndQuery);