?
Solved

javascript does not run properly when called from ASP:Button object

Posted on 2014-10-17
7
Medium Priority
?
241 Views
Last Modified: 2014-10-19
I am calling a javascript object from an ASP button using OnClientClick.  the javascript gets called (added an alert to test) but does not run...  the funny thing is if a create an html input button, the script runs as expected.  
here are the buttons...
<asp:Button runat ="server" ID="btnLookupCustomer" Visible="true" Text="Lookup Customer" Enabled="false" OnClientClick="openPopUp();" />
<input type="button" id="test" value="Lookup Customer1" onclick="openPopUp();" />

Open in new window

and the javascript...
 function openPopUp() {
        alert("i'm here");
       TINY.box.show({ iframe: "CustomerSelectPopup.aspx", close: true, width: 700, height: 600 });
     }

Open in new window


I don't understand why it would work with one control and not the other.
0
Comment
Question by:Jfb1126
[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
7 Comments
 

Author Comment

by:Jfb1126
ID: 40387935
also tried adding  UseSubmitBehavior="false" to the asp control with no avail...
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 40387960
I'm not a .NET dev but your asp code runs on the server before the page loads.  Your javascript runs on the client, after the page loads.

The best thing to do is to have the experts look at your rendered page.  Get your page on a public link.  If you are working locally, then just get the sample page somewhere public where it can be seen.  You can also render the html and place the html, css and javascript on jsbin.com or other playground.

More than likely you have a javascript error that is preventing this from working or the supporting files for the pop up are not loaded correctly, or you don't have your js code in a ready function.  It is hard to tell without seeing the full page.

http://sandbox.scriptiny.com/tinybox/
0
 
LVL 58

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 40388015
Try doing this  (add return before all to openPopUp).
<asp:Button runat ="server" ID="btnLookupCustomer" Visible="true" Text="Lookup Customer" Enabled="false" OnClientClick="return openPopUp();" />

Open in new window

Javascript
 function openPopUp() {
   alert("i'm here");
   TINY.box.show({ iframe: "CustomerSelectPopup.aspx", close: true, width: 700, height: 600 });
   // ADD THIS TO PREVENT DEFAULT CLICK BEHAVIOUR
   return false;
}

Open in new window

0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 11

Expert Comment

by:louisfr
ID: 40389015
As julianH wrote, return false from the code to prevent the button from submitting the form.
UseSubmitBehavior is not used to prevent a postback, only to change how the postback is done.
0
 

Author Closing Comment

by:Jfb1126
ID: 40389479
adding the return to the call worked.  

thank you,
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 40389758
You are welcome - thanks for the points - good luck with your project.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 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