Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an intialize method which I retrieve on button click.

After I click button the output is generated and this is fine but the output is gone after a second.

After I click again the output comes back but us gone again with in second.

<input type="submit" onclick = "initialize(); return false;" value="Go!" />

Help!
Posted
Updated 2-Sep-10 22:43pm
v3
Comments
Dalek Dave 3-Sep-10 4:44am    
Edited for Readability, Spelling and Grammar.

If you don't want to post back the page, change onClick event to OnClientClick.

EDIT ON:

I am sorry, I didn't realize it's an input element and not <asp:Button.
Here is the correct answer:
You have 2 options:
1) Use input type="button". But only if you don't want to post back the page.
2) Put return false; inside the initialize function. And change return false to return true;
So the line will be like:
XML
<input type="submit" onclick = "initialize(); return true;" value="Go!" /> 

The last line in the initialize function will return false.

NOTE: I have assumed you don't want to post back the page and initializing the control using Javascript.

EDIT OFF
 
Share this answer
 
v3
Comments
Sandeep Mewara 3-Sep-10 11:30am    
Sorry Ankur! But it's a HTML control.
Input would not have a 'OnClientClick' property exposed.
Simon_Whale 3-Sep-10 11:41am    
http://www.w3schools.com/tags/tag_input.asp shows events that you can use
Ankur\m/ 3-Sep-10 11:47am    
Oh, I didn't realize it. :doh:
I will edit it to add correct answer.
i don't know what you want get !!
i guess you may need as follows

<input type="submit" onclick = "return btnClick();" value="Go!" />  

<script type="text/javascript">
var isFirstClick = true;//need a varable
function btnClick(){
    if(isFirstClick ){
       initialize();
       isFirstClick =false;
       return false;      
    }else{
        return true;
    }

}

</script>
 
Share this answer
 
Try:
XML
<input type="submit" onclick = "if(initialize()) return false;" value="Go!" />


Return true from Initialize() method once you are done.
 
Share this answer
 
Comments
Ankur\m/ 3-Sep-10 11:49am    
I guess, he is already doing that because the page post backs.
I am editing my answer to add correct answer.
Sandeep Mewara 3-Sep-10 11:51am    
No, what he is doing is something different. The difference can be seen doing a view source of the page - look onclick event.
Ankur\m/ 3-Sep-10 11:59am    
Didn't get you. *confused*

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