Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,

Here my question is how can stop the page_load event when i press button.

i want to execute only Button Click Event. is it possible???

Ok,

When I Was Set
C#
if (!Page.IsPostBack)
{
   LoadCompany();
   LoadDesignation();
   LoadCategories();
   LoadStatus();
}

All Above Methods For the bind DropDownList.

Then On Button Click Event Not Execute this Code so my All Methods Not Call and so that My DropdownList show blank value.
and on button click not execute proper selected dropDownlist value.



Pleas Help Me.
Thank You.
Posted
Updated 30-May-12 0:28am
v3
Comments
John Orendt 30-May-12 5:54am    
Short answer is No. However you can leave the page_load method blank.
Prosan 30-May-12 5:55am    
why you want to do so. and what do you want to do in button click event
John Orendt 30-May-12 6:00am    
You probably want to use IsPostBack flag in Page_Load

Hi ,
You can't it's Default behavior for button , Instead of using Server side controls use HTML INPUT and use JavaScript
Best Regards
M.Mitwalli
 
Share this answer
 
No.
When your user presses a button, it starts an instance of your application on the server and automatically executes the page_load event.

Instead, use IsPostBack to prevent the page load event changing user data - when the used presses a button it will be set to true.
 
Share this answer
 
It depend on your code that you written on the button click event, If you do not want to postback the page then I suggest you to use jQuery Ajax from the following LINK. In this technique postback not happen and hence only your button click code will work.
hope this help you
 
Share this answer
 
v2
I have to say, you can do it. why don't you rethink on the desired behavior and redesign your strategy.

Although, If your button click event is not dependent on any other control of the page and is not using any other values from the page, you can disable the postback and move the code of button into other page that can be called using XMLhttpRequest. (perhaps that not what you are looking for)
 
Share this answer
 
Use PageMethod to avoid full page life cycle. It will directly hit a method in the code behind.
Here: PageMethod[^]
 
Share this answer
 
i was change EnableViewState property of the DropDownList set as Fals..
so it create problem.
Now Set as true then it work Proper.

Thanks.
 
Share this answer
 
it is not possible. if you want to redirect to any page than you can set PostBackUrl property. than your page will redirect to on which page you define in postbackurl without postback. if you are not redirecting to another page than in page_load check ispostback property to nothing to do in pageload event.
 
Share this answer
 
v3

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