1

How can I call an ASP function and a Javascript function from one HTML Button OnClick event? -- Not using ASP.NET

onclick="SetDiv('titel', 'trSchrijver', 'boek')"

JS

Combined with

onclick="<% boek.GetSchrijver %>"

ASP

Thanks!

Wesley Lalieu
  • 487
  • 2
  • 8
  • 22

2 Answers2

0

Maybe you want to look into this framework for Classic ASP with easy AJAX support: http://ajaxed.org/

gpinkas
  • 2,291
  • 2
  • 33
  • 49
-1

The ASP Button control has a OnClientClick and a OnClick attribute. The first is used to define a JavaScript string to be executed client-side, the second is used to define an event handler method (an ASP function) to be executed server-side after a postback. You can use both.

<asp:Button id="Button1"
   text="Execute ASP and JS"
   onClientClick="alert('I am JavaScript!')"
   runat="server" onclick="Button1_Click" />

In your codebehind file:

void Button1_Click (object sender, EventArgs e)
{
  // Do C# stuff ...
}

Documentation:
- http://msdn.microsoft.com/library/system.web.ui.webcontrols.button.onclick.aspx
- http://msdn.microsoft.com/library/system.web.ui.webcontrols.button.onclientclick.aspx


If you do not want to use the ASP Button control, you can instead use the JS function __doPostBack() in a normal HTML element.
<input type="button" id="btnSave"
  onclick="doSomething(); __doPostBack('btnSave ', 'parameter');"
  value="click me"/>

In your codebehind:

public void Page_Load(object sender, EventArgs e)
{
  string parameter = Request["__EVENTARGUMENT"]; // parameter
  // Request["__EVENTTARGET"]; // btnSave
}

See How to use __doPostBack() where I got the example from.

Community
  • 1
  • 1
djk
  • 943
  • 2
  • 9
  • 27