[RESOLVED]Calling asp:Buttons server side event from jQuery


I’m trying to call a button’s OnClick event from jQuery. Here is a simplified version to demonstrate:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="TheBigIdea.FE.Test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <script src="Scripts/jquery-1.10.2.js"></script>
        <script type="text/javascript">
            function Test() {                     

            function Test2() {
        <form id="form1" runat="server">
                <asp:Button ID="Button1" OnClientClick="Test()" runat="server" Text="Button" />
                <asp:Button ID="Button2" OnClientClick="Test2()" OnClick="Button2_OnClick" runat="server" Text="Button" />

This calls the client side method Test2(). But I want to fire the server side event OnClick. I only added Test2() as nothing was happening and I suspected that $("#<%=Button2.ClientID%>").click(); was trying to fire a client side event. I changed it to various
versions similar to: $("#<%=Button2.ClientID%>").onclick(); but nothing has worked yet.

Please help if you can.



You need to hook up the server event. You need to specify the onclick handler. Currently the button has no handler specified. 


Can you show how I specify the onclick handler please?

Like the onclick that you have in button2. Plus the actual handler in the code behind which button2 should have. So follow what you’ve done for button2 basically. 

Leave a Reply