Using Javascript functions for ASP.NET Events

Need to call Javascript functions for ASP.NET button events

Page 1 of 1

1 Replies - 4194 Views - Last Post: 30 December 2008 - 11:36 AM Rate Topic: -----

#1 D1gitalIce   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-October 08

Using Javascript functions for ASP.NET Events

Posted 30 December 2008 - 11:32 AM

I am trying to figure out how to call a Javascript function when a user clicks an ASP.NET button.

I have a GMaps.js file that I wrote which contains a bunch of functions related to the Google Maps API. In my ASP.NET page, I have a link to that file, a body attribute that loads the initialize function in my Javascript file, and a divider with the id of canvas to contain the actual map object.

Here is where I get stuck. I have a Javascript function called getDirections. This contains two strings plus a call to gDirections (Google Maps API). I have a text box and button in my ASP.NET page like this:

<asp:TextBox ID="addressinput" runat="server"></asp:TextBox>
<asp:Button ID="gobutton" runat="server" Text="Go!" />

What I am looking for is a way to have the onclick attribute of my button to be tied to a Javascript function in my external Javascript file. I also need a way to allow a variable in my Javascript to be assigned the value of addressinput.Text (the textbox listed above). Is there any possible way to do this?

Is This A Good Question/Topic? 0
  • +

Replies To: Using Javascript functions for ASP.NET Events

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Using Javascript functions for ASP.NET Events

Posted 30 December 2008 - 11:36 AM

You would use the OnClientClick Property of your .Net server control, in this case your button

<asp:Button ID="gobutton" runat="server" Text="Go!" OnClientClick="CallYourJSFunctions" />

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1