Solved

Calling a Java script method from Asp.net, plus why is false returned?

Posted on 2009-07-01
4
232 Views
Last Modified: 2012-05-07

Hi, my Java Script is a little weak so bear with me.
My situation is that I have an Asp.net button. When it is pressed, it returns "false"
and my Ajax code works great. I need to enhance the code so that not only does it return
false, but it also calls another Java script method.

I tried returning false from the new Java script method, but it is not working for me. Can anyone tell me
what I need to do in order to have my New method called and then also to return false?

Here is my current code:
<asp:Button ID="btn_Animate" runat="server" Text="Animate" OnClientClick= "return false;" />


I need to enhance it so that it calls this method and also returns false. Note that I tried using the following
method but it did not work.


<script type="text/javascript">
function NewMethod(coord1,coord2) {

    coord1 = coord1 + coord2;
    return false;
}
</script>

Also dear experts I don't understand why false is returned in the first place? maybe you could help me understand
that as well. I will increase the points to accomidate the extra help in explaing why false need to be returned.
0
Comment
Question by:brgdotnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
ddayx10 earned 160 total points
ID: 24759301
Two options:

<asp:Button ID="btn_Animate" runat="server" Text="Animate" OnClientClick= "return NewMethod('parm1','param2');" />
<script type="text/javascript">
function NewMethod(coord1,coord2) {

    coord1 = coord1 + coord2;
    return false;
}
</script>


OR

<asp:Button ID="btn_Animate" runat="server" Text="Animate" OnClientClick= "NewMethod('parm1','param2'); return false;" />
<script type="text/javascript">
function NewMethod(coord1,coord2) {

    coord1 = coord1 + coord2;
}
</script>
0
 
LVL 5

Assisted Solution

by:mallcore
mallcore earned 40 total points
ID: 24759338
How about we do it something like this


<asp:Button ID="btn_Animate" runat="server" Text="Animate" OnClientClick= "return NewMethod();" />
<script type="text/javascript">
function NewMethod(coord1,coord2) {
 
    coord1 = coord1 + coord2;
    return coord1;
}
</script>

Open in new window

0
 
LVL 20

Expert Comment

by:ddayx10
ID: 24759378
Ah I forgot to answer the "Why is it false?" part.

Well if you return true from an action, let's say a button click, then the normal operation of that action will continue. In the case of a submit button it will post back the page. In the case of a link it would take you to another page.

If you return false from an action then the initial action is canceled. Button no longer causes the page to post back, just the JS function runs...etc.
0
 
LVL 2

Author Comment

by:brgdotnet
ID: 24766739
Thanks guys, you are awesome! It was the "return" part of the code that I was missing on the onButtonClick. So it is working now just great.
ddayx10 was the first to answer so I will give him the most point.

I need to take the time to figure out how to help others on this forum, as I would like to respond to other peoples questions as they need help. Have a great holiday!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
reading excel file in .net 2 45
YouTube API get the Video Tags - vb.net 7 50
Need help for captcha 2 40
Why am I losing my session variable value 11 37
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question