Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1520
  • Last Modified:

Adding Javascript "if-else" to this onClick

I have a js code like this:

 function test()
   {  alert("hello") ;  return true;}

***I have a button like this:
<asp:Button ID="btnLookupByPostalCode" runat="server" OnClick="btnLookupByPostalCode_Click"  />

  -- I want to add something like this :  onClick= "if return(test() == true) { btnLookupByPostalCode_Click; } "

can I do that?? I get errors...
0
Camillia
Asked:
Camillia
  • 4
  • 2
2 Solutions
 
hieloCommented:
You can only use return within a function. This is incorrect:
if return

try:
<asp:Button ID="btnLookupByPostalCode" runat="server" OnClientClick="if( test() ){btnLookupByPostalCode_Click();}"  />
0
 
CamilliaAuthor Commented:
that btnLookupByPostalCode_Click is ASP.Net's onClick event for the button. It's not a JS function so I get an error that object is required.

I dont think I can call a ASP.Net onClick event from JS. no?
0
 
spoxoxCommented:
This javascript will work:

<script type="text/javascript">
function test() {
return true;
}
function btnLookupByPostalCode_Click() {
alert("Testing");
}
</script>


<button onClick="if (test()) {btnLookupByPostalCode_Click();}">Click me</button>
0
Industry Leaders: 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!

 
CamilliaAuthor Commented:
As I said : btnLookupByPostalCode_Click is NOT a javascript function. It's C#'s onClick event for the button. That code is NOT a JS code. It's C# in code behind.
0
 
CamilliaAuthor Commented:
thanks, let me see.
0
 
CamilliaAuthor Commented:
This should do it but I cant get past one issue. I will close this question and open another one. Thanks,
0

Featured Post

Independent Software Vendors: 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!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now