Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-07-01
4
Medium Priority
?
237 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 640 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 160 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

604 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