Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
when popup window on , i give one value and click on button. problem is hear that when i click on button it will load the page and inserted value will clear . so, i want that when i click on button it should not tack load and my button click event must me run.

<asp:Button ID="btnfirstnext" TabIndex="1" runat="server" Text="Next" class="next1 action-button" OnClientClick="return false;" OnClick="btnfirstnext_Click" />

What I have tried:

OnClientClick="return false;" when i use this it will not fire a button click event
and i if i remove OnClientClick="return false;" , page will be load and i don't want it.
Updated 6-May-16 19:35pm

1 solution

OnClientClick is an attribute for Asp:Button which takes boolean value as input from a javascript code or a function.
if the OnClientClick value is true, it will fire (PostBack) the server Event (OnClick), else it will remain same in that page.

OnClientClick ="return true" // It will fire OnCick event 

OnClientClick ="return false" // It wont do any action.

Now you can write your code which suits your requirement.

By defalut the OnClientClick is set to true, if you have not added the attribute in the tag.

if you want to call it from a function.

function SomeJsFunction()
          // write some logic/Validation/etc in such a way that it returns boolean value ( true|false)
          if (....Your Code.....)
              return true;
              return false;

OnClientClick="return SomeJsFunction();"
Share this answer
Kumbhani Bhavesh 7-May-16 1:40am    
but i want both .
i mean i want click event and page should not load.
Karthik_Mahalingam 7-May-16 1:41am    
what is your actual requirement, pls elaborate it.
Karthik_Mahalingam 7-May-16 1:40am    
Click event means PostBack , this is ASP.NET functionality..
Kumbhani Bhavesh 7-May-16 1:51am    
Kumbhani Bhavesh 7-May-16 2:01am    
there is any solution that page should not load and button click event must be run ???

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