0

Ok so this is a snippet of my aspx file, I am trying to call a "hello world" function from the 'test.js' file. This is obviously not working, could someone please recommend me a good way of doing it?

<asp:ScriptManager ID="ScriptManager1" runat="server">
 <Scripts>
 <asp:ScriptReference Path="\App_JavaScript\test.js" />
 </Scripts>
</asp:ScriptManager>
<asp:Button ID="timebutton" runat="server" Text="clickme" OnClick="javascript:getData();" /><br />
asked Mar 2, 2010 at 22:55

3 Answers 3

4

OnClientClick

<asp:Button ID="timebutton" runat="server" Text="clickme" OnClientClick="javascript:getData();" />
answered Mar 2, 2010 at 22:58
Sign up to request clarification or add additional context in comments.

1 Comment

i am not worthy. i shall delete myself.
0

Use jQuery to assign the function to the click event of the button.

 <script type="text/javascript" src="\App_JavaScript\test.js"></script>
 <script type="text/javascript" src="jQuery.js"></script>
 <script>
 $(document).ready(function(){
 $('#timeButton').click(getData);
 //Use below instead if you are using Master Pages
 //$('#<%= timeButton.ClientID %>').click(getData);
 });
 </script>
<asp:Button ID="timebutton" runat="server" Text="clickme" />
answered Mar 2, 2010 at 23:02

3 Comments

This will not work. The rendered ID of a server side button is not what you place in the ID field.
Unless you're talking about .NET 4.0, this will not work. You still need to use the ClientID and not just #timebutton
If the web form is NOT inside a master page, then will the client ID not be the same as the ID specified? It's been a while since I've worked without master pages so I could be mistaken.
0

If you need a postback to occur you can also use ScriptManager.RegisterClientScriptBlock

answered Mar 2, 2010 at 23:09

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.