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!
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!
Maybe you want to look into this framework for Classic ASP with easy AJAX support: http://ajaxed.org/
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
<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.