How can you raise server side event from client side

Let's say I have an event on server side that handles button_click. how can I raise that event from client side using AJAX.

4/1/2009 2:31:36 AM 13973 articles. 1 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 35
Get it on Google Play
Get it on Apple App Store

You can create a script in a string variable, and register with

string script = "alert('ciao!')";
ScriptManager.RegisterStartupScript( this, this.GetType(), "Alert", script, true );

If this answers your question, please select 'mark as answer' thanks!

Andrea Dottor
Microsoft MVP - ASP/ASP.NET
4/1/2009 10:15:54 AM

For buttons you can use JQuery  to click the button.  It varries.  Some controls you can just call __dopostback with javascript.  Submit buttons its easier to click them in code.  

Example Below button3 that clicks button2 using javascript (ajax);

Note: example uses google.load for jquery.

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <script src="" type="text/javascript" ></script>
<script type="text/javascript">
    // Load jQuery
    google.load("jquery", "1.3");
    function Button3_onclick() {

        <asp:Button ID="Button2" runat="server" Text="asp:Button" />
        <input id="Button3" type="button" value="html:button" onclick="return Button3_onclick()" />
        <input id="Button1" type="button" value="html:nothing" />


Good Luck

4/1/2009 12:39:10 PM


Please check this post:

You can call JavaScript __doPostBack('ButtonUniqueID','') to do postback. Before that, please make sure you have define __doPostBack function on the page, and make sure the button is as the trigger of UpdatePanel.

Vince Xu
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
4/3/2009 5:43:13 AM

Let's say I have an event on server side that handles button_click. how can I raise that event from client side using AJAX.


You can call a button click event using javascript this way

var btn = document.getElementById("<%=Button1.ClientID%>");;

MAKMark as Answer if this reply helps you
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
4/3/2009 6:01:00 AM


I agree with MAK and you can use the syntax given by him to raise the click event . Just in case if you are using ajax then you can cut short the syntax to :- $get('<% = Button1.ClientID %>').click().

Button click event causes postback for the current page . Generally page postback takes place via two mechanism ie Submit button and _doPostBack method . The problem with Submit button approach is that it relies quiet heavily on the presence of Submit button for page submission . So all server controls registers the javascript _doPostBack() method as event handler for one of their events .I will suggest you to take this approach to raise server side events as suggested by Vince.

Pawan Mishra
“The greatest compliment that was ever paid to me was when one asked me what I thought, and attended to my answer.” - Henry David Thoreau
4/3/2009 7:14:49 AM

just read this article u wil understand..

4/3/2009 8:01:45 AM

Similar Artilces:

Firing both Client side event and server side event for server side button
I am having some difficulties getting this to work.. I have button_click ( and ClientClick (Javascript).  Javascript is firing fine.  Server script is not. may be you have return return false in the in the javascript which is why its not firing server side event.You should add javascript evelt like thisbutton1.onclientclick = "functionname" Function should nopt return false. Vikram www.vikramlakhotia.comPlease mark the answer if it helped you...

Can AJAX from the server-side initiate an update of a client-side Update Panel ?
I have a website where multiple users are updating various pages of data. If a user updates a particular section that other people are looking at I'd like to be able to trigger an update in the other peoples' Update Panels. Is this possible?RegardsMatthew You can update a panel from server-side code, by simply use the Update method of the UpdatePanel that you want to update./Fredrik Normén - fredrikn @ twitterMicrosoft MVP, MCSD, MCAD, MCTASPInsidersMy Blog How do I get an event on one user's page to update other users' pages asyncronously? My first thought was to record the events of...

Help with client side events Vs. server side events
Hi, Can someone look as the following script and tell me why marking the check box doesn't generate a client side event eventhough there's: onclick="checkClick()"? marked.  Thanks in advance, Sivan <%@ Page Language="c#" %><HTML> <HEAD>  <meta name="vs_targetSchema" content=""> </HEAD> <body>  <SCRIPT language="c#" runat="Server">  void Page_Load(object s, EventArgs e) {  if (!Page.IsPostBack)  {   Label1.Text = Label...

Client side/server side event race.
 Hi.  I've got a page that 1) Takes some text fields as input2) Does some math calculations on the input (server side via a "calculate" button click)3) Then opens a new window with some detailed information (client side, via a "view report" button click)The server needs to "calculate" before the user can click "view report" so I start with "view report" disabled.  I've got input validation on the "calculate" click, and at the end, I enable the "view report" button.  Everything is working well wi...

Client Side events and Server side binding
I want to filter a dataset, server side and bind it to a select control. Problem is my filtering must be done based on the text written by the user in a text input. To get this text i'm using client side keyboard events. I tried to use client side binding and it works fine, but the problem is my dataset has more than 10000 rows, and so the performance is awful. Only thing i can do i think is to rebind the select control to a filtered dataset, improving performance. This is my code at the moment: In the aspx: static HtmlSelect _control = null; [WebMethod(EnableSession = true)] publi...

how can I update server side control purely by events triggered by server side timer
Currently I am writing code based on google earth API. Basically server writes a piece of KML info every second,(using AddHandler aTimer.Elapsed, AddressOf OnTimer) then the browser uses XMLHttpRequest to retrieve this KML and display it on the Google Earth plugin. This part works fine, however when there is no more KML to write on the server, I want to disable some buttons running on the server. Unfortunately I cannot achieve it. If I use update method of UpdatePanel (I put those buttons in the UpdatePanel), it pops up the error of "The Update method is called during or after the page...

executing my own function @ server side for a client side event
hi all, I have a client side dropdownlist control with onchange event. I am calling form1.submit() method in onchange event. is it possible to catch that event at server side ???ThanksPrashanth.J Not if you call form1.submit(). Try replacing that with <%= ClientScript.GetPostBackEventReference(DropDownList1, string.Empty) %>; Then in the Page_Load handler server-side: private void Page_Load(object sender, System.EventArgs e){ if ( this.IsPostBack ) {  // Place any code that needs to be executed ONLY on a post-back here.  string eventTarget = (this.Req...

Jscript, moving from client-side to server-side (.NET)
Hey all I’m working translating a web-app written in client-side Jscript to run on the server-side as JScript.NET. Without needing to get too specific, I am using Jscript because the original page aggregated raw data to produce statistical results (this was done dynamically based on user 'sort-by' options). The final output is an html report that can be emailed. Because this is currently being done on the client side, as the raw data grows the load-time grows as well (to the point that has almost become unusable). I’m posting here to see if anyone has any experi...

Stop execution of server side event from client side
Dear All  I have a text box and i wrote code on the server side event( On Text Change). So when i write something on the text box it goes to server and execute the server side code. Now i want to control this sever execution from client side. i mean i want to cancel this postback from client side under some conition. can anyone plz help me? Regards Sure if you let us know what you want to be done. here is an example <asp:textbox id="txtFile" OnTextChanged="javascript:RefreshPage();" Visible=true Width=500 Runat=server/> function RefreshPage() { &nb...

doing client-side action after server-side event ends
 I have a asp-button;I want it to perform a client-side action after completion of the sever-side action((like:calling a javascript function after the click event of the button ends); You can inject some javascript from the server side button click event so that when the page renders on the client side it will invoke the function or javascript fragment. You can use the method Page.RegisterStartupScript to inject javascript, or you can assign the javascript fragment to a literal control which would be interpreted when the page renders on client side.  Can u add some code snippe...

Calling server-side methods from client-side event
Hello,i'm novice in client-side script and i have a simple question: is it possibile to call a server-side method (ex. c# managed code) from a java script client-side function linked to an event?Thanks all  Luca GuccioneGenova, Italy Yes you can. It's very easy using web methods from code behind, jquery and the script manager. See this very good blog post explaining the steps: mySoZa lucaguccione: Hello, i'm novice in client-side script and i have a simple quest...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in ( required field, range validator and others) question is the required field validator is a server side control. So does that mean that it does a post back? it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

Accessing server-side variables from client-side events
This is a multi-part message in MIME format. ------=_NextPart_000_00E8_01C04D70.7EAC7080 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable In a client-side itemchanged function, how can I set a server-side = variable?? I simply need to execute the following: psSession.SetValue("userID", user_id); I'm sure there's a way to trigger server-side script and pass in = variables. Any suggestions?? Thanks. ------=_NextPart_000_00E8_01C04D70.7EAC7080 Content-Type: text/html; charset="iso-8859-1" ...

Server Side control invoking a Client Side event
I need to figure out how to get a server side control to process the "OnMouseOver" event. Since server side controls do not have the onmouseover event associated with them, how would you make for example, a DropDownList have a "OnMouseOver" event associate with it? The DropDownList must be server side. I guess the idea here is to set client-side events on the server-side control. Any help will be appreciated. You may try something like this: In server side code DDL1.Attributes.Add("onmouseover", "javascript:alert('Hi')") Th...

Web resources about - How can you raise server side event from client side -

X.Org Server - Wikipedia, the free encyclopedia
X.Org Server refers to the X server release packages stewarded by the X.Org Foundation , which is hosted by , and grants public ...

NVIDIA Announces Tesla M40 & M4 Server Cards
Slowly but steadily NVIDIA has been rotating in Maxwell GPUs into the company’s lineup of Tesla server cards. Though Maxwell is not well-suited ...

Price Drop: MyAudioStream Pro UPnP audio player and streamer: gather your music collection from your ...
MyAudioStream Pro UPnP audio player and streamer: gather your music collection from your PC, NAS, UPnP servers, Windows Media Player or iTunes ...

Intel Rising; Street Likes Stable Outlook; Server Cracks Appear
... ( MU ) might not move fast enough with the “ 3D Xpoint ” technology the two are developing. Some cracks are appearing in Intel’s server market ...

Twitter faces local computer server demand by Russia
Russia's internet watchdog says Twitter will have to set up local data centres, having previously ruled out such a move as unnecessary.

VertrigoServ is an easy-to-manage WAMP server
Setting up a web server can be a lengthy and complicated process, with so many components to download, set up and manage. A WAMP server (Windows, ...

Poll: 68 Percent Call Hillary Clinton Email Server ‘Illegal’ or ‘Unethical’
Younger voters are the largest demographic saying Hillary Clinton behavior was unethical, and half saying they think she did something wrong ...

Morgan Stanley kicks tires on ARM servers, wants a rival for Intel
A lot has been written about servers based on ARM processors , but there's little data about how many are actually being used in production. ...

Joe’s Crab Shack Tests No-Tipping Policy, Raises Server Wages To $14/Hour
... expand it to all 113 locations in the U.S. To make up for the lost gratuity, the company says it will implement a new set wage practice. Servers ...

Quanta lands server orders from Uber and Wiwynn from Twitter
Seeing competition growing fierce, Quanta Computer and Wiwynn, a server subsidiary of Wistron, have turned to target second-tier Internet service ...

Resources last updated: 11/21/2015 10:56:19 AM