[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

call function

Posted on 2016-10-05
8
Medium Priority
?
65 Views
Last Modified: 2016-10-12
Hi,

this is my code
 <asp:TextBox id="SqFtX" runat="server" Width="40px" onkeypress="return isNumber(event,$('#SqFtX').val())"></asp:TextBox>

Open in new window


I am checking to see if user entered numeric value. Is there a way to call another function at the same time? such as

 <asp:TextBox id="SqFtX" runat="server" Width="40px" onkeypress="return isNumber(event,$('#SqFtX').val()); MyFunction();"></asp:TextBox>

Open in new window


Thanks
0
Comment
Question by:mcrmg
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 20

Expert Comment

by:Russ Suter
ID: 41830854
Basically, no. What you're actually calling is an event handler. An event can have only one event handler assigned to it. It would be possible to call a function from within the event handler. It's also possible to switch on some variable within the event handler so you can optionally run additional functions.
0
 
LVL 9

Expert Comment

by:Karen
ID: 41830942
It is the "return" statement that is stopping the second function call.
Depending on what you want, any of the following should work

isNumber(event,$('#SqFtX').val()); MyFunction(); return;

var retval = isNumber(event,$('#SqFtX').val()); MyFunction(); return retval;

var retval = isNumber(event,$('#SqFtX').val()); if (retval) { MyFunction(); } return retval;
0
 

Author Comment

by:mcrmg
ID: 41831624
I think this should work

var retval = isNumber(event,$('#SqFtX').val()); if (retval) { MyFunction(); } return retval;

When the value is numeric, it will call MyFunction.  But for some reason, it is not.  Am I missing something?  thanks

<td><asp:TextBox id="SqFt" runat="server" Width="80px" onkeypress="var retval = isNumber(event,$('#SqFtX').val()); if (retval) { MyFunction(); } return retval;"></asp:TextBox>

Open in new window


    protected void MyFunction(object sender, EventArgs e)
    {
        System.Windows.Forms.MessageBox.Show("HERE");


    }

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:mcrmg
ID: 41831898
Is there a way to call to a code behind function?  This is my code, it looks like it posts back, but not getting to the function.  I would like to see if there is a way to verify if the entry is numeric then call to a function.  thanks

<asp:TextBox id="SqFt" runat="server" Width="80px" AutoPostBack="True" onkeypress="return isNumber(event,$('#SqFt').val())" Onclick ="MyFunction"></asp:TextBox>

Open in new window

0
 
LVL 9

Expert Comment

by:Karen
ID: 41832824
It is different depending on whether MyFunction is in the javascript or in your code-behind. Sorry, I thought it was a javascript function you wanted to call.
When do you want the code-behind to execute? While the user is still typing in the text box (i.e. triggered by keypress event) or after they have finished typing?
0
 

Author Comment

by:mcrmg
ID: 41833590
if it is possible, I would like to "block" user from entering non-numeric value (during or after validation is okay), then once they leave the field, a code behind function will be called.  That function is basic grabbing the value that user just entered and do some calculations.  thanks
0
 
LVL 20

Assisted Solution

by:Russ Suter
Russ Suter earned 1000 total points
ID: 41834330
This is the sort of thing that Javascript is excellent at. You can have click validation on the client side which can short circuit postback events if the result is not as desired. Something like this:
<asp:TextBox Id="myTextBox" onkeypress="validateKeyPress();" onclick="myTextBox_Click" onclientclick="return isInputValid(this, event);"></asp:TextBox>

Open in new window

What happens is the onclientclick event (client-side click event) is handled first. Somewhere you have a Javascript function that looks like this:
function isInputValid(sender, eventArgs) { ... }

Open in new window

That function returns a true or false value. If the returned value is false then the server-side click event is prevented.

DISCLAIMER: The above was just spit out of my brain without any checking but essentially that's the correct idea.
0
 
LVL 9

Accepted Solution

by:
Karen earned 1000 total points
ID: 41836267
You just have to split your two tasks up.

Your code to stop the user from entering non-numeric characters is done in onkeypress.
Then, the same code is executed in onchange. If it fails the test, then it returns "false" and OnTextChanged is not executed. If it passes the test, then OnTextChanged is executed.

<asp:TextBox id="SqFt" runat="server" Width="80px" AutoPostBack="True"  onkeypress="return isNumber(event,$('#SqFt').val())" onchange="if (!isNumber(event,$('#SqFt').val())) return false;" OnTextChanged="MyFunction"></asp:TextBox>
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

656 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