Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.
I have a page with several buttons. I need one of the buttons to submit the form and the others to perform tasks on the page without reloading it from the server. For some reason, each time a press any button the page is reloaded (enters Page_Load()).
Any ideas on what I'm doing wrong?

Thanks
Posted
Comments
Sandesh M Patil 13-Dec-10 10:33am    
You mean you dont want to post back the page on the click of second button?

You are not doing anything wrong, that is the way ASP.NET functions.

If you want actions without reloading the page then you must use AJAX.
 
Share this answer
 
Comments
JimCaplan 13-Dec-10 10:46am    
I see. Thanks.

Is there a way to bypass this? How complicated is it to add AJAX code for this purpose?
[no name] 13-Dec-10 11:02am    
No there is no way to bypass this.
How complicated is AJAX? How blue is the sky?
How complicated AJAX is depends on your skills and what you are trying to accomplish
 
Share this answer
 
See my previous answer on this

Preventing postback[^]

You can 'prevent postback' so the buttons do not call back to the server.

If that's what you want, you'll need to run some sort of client side functionality to do something when you click the button, normally some javascript.

Otherwise, if you want server side code to run, just ignore the postbacks in your Page_Load event - you can write code like

if (!Page.IsPostBack)
{
    // Do something here that only happens the first time the page loads
}


Then, just create event handlers for your buttons and write code accordingly.

What approach you should use depends entirely on what you're trying to achieve
 
Share this answer
 
Comments
JimCaplan 13-Dec-10 11:16am    
Thanks, IsPostBack is a great solution! Solves my problem completely.
[no name] 13-Dec-10 21:45pm    
However this does not prevent the page from reloading or going through the PageLoad event. The original question was asked to avoid this. "without reloading it from the server"
Dylan Morley 14-Dec-10 4:25am    
I actually gave 2 answers here. One was to use javascript, avoiding any reload. The other was to test for IsPostBack in the PageLoad

Since the answer was accepted, I think the OP might have worded his question badly & obviously didn't know about the IsPostBack property.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900