Help with client side events Vs. server side events


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,


<%@ Page Language="c#" %>
  <meta name="vs_targetSchema" content="">
  <SCRIPT language="c#" runat="Server">
 void Page_Load(object s, EventArgs e)
  if (!Page.IsPostBack)
   Label1.Text = Label1.Text + "<P>page_load first time, ";
   Label1.Text = Label1.Text + "<P>page_load postback, ";
 void Page_Unload(object s, EventArgs e)
  Label1.Text = Label1.Text + "Page_Unload, ";
 void buttonServerClick(object s, EventArgs e)
  Label1.Text = Label1.Text + "server button click, ";
 void textServerChange(object s, EventArgs e)
  Label1.Text = Label1.Text + "server text change, ";
 void checkServerClick(object s, EventArgs e)
  Label1.Text = Label1.Text + "server checkbox click, ";
 void checkServerChange(object s, EventArgs e)
  Label1.Text = Label1.Text + "server checkbox change, ";
 void listServerClick(object s, EventArgs e)
  Label1.Text = Label1.Text + "server listbox click, ";
 void listServerChange(object s, EventArgs e)
  Label1.Text = Label1.Text + "server listbox change, ";
  <SCRIPT language="javascript">
 function buttonClick()
  span1.innerHTML = span1.innerHTML + "button clicked, ";
 function textChange()
  span1.innerHTML = span1.innerHTML + "textbox changed, ";
 function checkClick()
  span1.innerHTML = span1.innerHTML + "checkbox clicked, ";
 function listChange()
  span1.innerHTML = span1.innerHTML + "listbox changed, ";
  <FORM runat="server" ID="Form1">
   Name: <input type="text" onchange="textChange()" onserverchange="textServerChange" id="txtName"
    runat="server" NAME="txtName">
    <SELECT id="lstTitle" onchange="listChange()" onserverchange="listServerChange" onserverclick="listServerClick"
     runat="server" NAME="lstTitle">
     <OPTION selected>Software Engineer</OPTION>
     <OPTION>Software Tester</OPTION>
     <OPTION>Program Manager</OPTION>
   <P><asp:checkbox autopostback="True" onclick="checkClick()" onserverclick="checkserverclick" oncheckedchanged="checkServerChange"
     runat="server" id="Checkbox1" text="Certified Professional" /></P>
   <P><INPUT type="submit" Value="Save" onServerClick="buttonServerClick" onClick="buttonClick()"
     runat="server" id="Submit1" name="Submit1"></P>
   <p>Client-Side events: <span id="span1" runat="server" />
   <p>Server-Side events:
    <asp:label id="Label1" runat="server" /></p>

4/13/2007 2:41:06 AM 93655 articles. 6 followers. Follow

7 Replies

Similar Articles

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

are you sure it didn't call checkClick()? did you add an alert() inside and make sure a popup showed? cuz I see absolutly nothing wrong with it. 

Liming Xu
Jumptree ASP.NET 2.0 Project Management - With Source Code, Free to Non Profit Org and Effectively Manage Projects/Tasks/Milestones
4/13/2007 4:01:01 AM

You can try to add the below code at page_load

CheckBox1.Attributes.Add("onclick","alert('Checking is working')");

then if it does work then you can call the checkClick function, try to put alert('Testing') at the start of the checkClick() function to see when you call it if it does work or not. if also yes then you have a problem with your javacript code.


Haissam Abdul Malak
| Blog |
4/13/2007 5:48:47 AM

Thanks for your answers but the problem was that the AutoPostBack property was set as TRUE, once I defined it to be FALSE it was fine.

It seems as if the control was sent to the server every time it was clicked so it ignored the client side event- Does it make sense?

 If it does, please explain to me why the page wasn't refreshed every time I checked the chec box when AutoPostBack property was set as TRUE?doesn't it mean the page is sent to the server every time I mark the check box?


4/13/2007 8:26:39 AM

I have tested the below scenario,

I used a checkbox with ID CheckBox1 and set it's AutoPostBack property to true then use the below line of code in the page_load event

CheckBox1.Attributes.Add("onclick","alert('Checking is working');");

When i run the application and click on the checkbox, the message appeared and after i clicked OK, it was postedback.

Maybe when you had AutoPostBack to true and you used the code, a javascript error happened that is why no postback occured. try to do the steps i mentioned in the start of this post.


Haissam Abdul Malak
| Blog |
4/13/2007 9:52:53 AM

Thanks, but it's still not working, I don't understand how this is possible...

Maybe I'll try running your code and I'll compare it with mine....??

4/13/2007 3:23:03 PM
Okay, I ran your code and the javascript was definitly called. I added "alert("is it called")" inside the function.. can't tell you though why the content wasn't updated... as i suspect that autopostback took over before your javascript could complete setting its content.
Liming Xu
Jumptree ASP.NET 2.0 Project Management - With Source Code, Free to Non Profit Org and Effectively Manage Projects/Tasks/Milestones
4/13/2007 4:46:56 PM
This is because the page is posted back, and the server recreate those controls and try to load their value from datas posted to the server.
But span1's value isn't posted, so it's always empty.
4/17/2007 6:06:24 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...

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...

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...

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...

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...

Call client side and server side events together.
I have one textbox on my aspx page.I want to validate amount in that textbox. If it exceeds 100 then the alert message should show that amount is bigger.And it should not go further. But if the amount is less than or equal to 100, then after checking the condition onclientside, it should to the server side TextChanged event.I have written a javascript function which is being called on "onchange" event of textbox and if the value is valid, then it should call serverside textchanged event of the same textbox.Please its urgent. Mark it as Answer if you find it Helpful.Shailen  ...

Calling Client Event From Server Side Click Event
Hi ,Would appreciate if someone could help me out with my issue as below Issue : This whole process Fetching Data from WebService ,Writing a File on Server from it Finally passing the path of file created to Browser so as to give User the option to either Open or Save the File at User end needs to be done in one click event.I am fine with Server event getting everything done but not sure how to open the file for end User.One way is using, not sure how I can do all the Server event and then using the FilePath , call client end suggest.Rega...

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. You can create a script in a string variable, and register withScriptManager.RegisterStartupScript string script = "alert('ciao!')";ScriptManager.RegisterStartupScript( this, this.GetType(), "Alert", script, true );If this answers your question, please select 'mark as answer' thanks!Andrea DottorMicrosoft MVP - ASP/ASP.NET For buttons you can use JQu...

How to fire a server side Sub after client side event?
Hi,  How can i fire a server side event after a client side event..? For example, just an example, i want to show a "message box" - The debugging one: MsgBox(stuffs), or calls any other functions which requires the clicked button's id? I took a look on stuffs like getPostBackEventReference()... Did i in the wrong way? Any help or quick sample would be very much appreciated!! :D Hi, you can call the doPostBack (first argument is the control-Id) method, see my code snippet:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Testpage.aspx.cs" Inhe...

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...

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" ...

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...

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...

Calling a client side control event from a server side function
I would like to know how to raise an event on a client side only control from a server side function.   For example, I have Button1 whose onclick is handled at the server. The logic behind the function will do 1 of 2 things, change the text of a label to indicate a problem or navigate to a new page.  I cannot use redirect because i need the new page to appear inside 2 of 3 existing frames.  I can manage this using an anchor on the client.  All I need to do is automatically click the anchor after I post back from the event.I tried the following line of c...

Web resources about - Help with client side events Vs. server side events -

MUD client - Wikipedia, the free encyclopedia
A MUD client is a computer application used to connect to a MUD , a type of multiplayer online game . Generally, a MUD client is a very basic ...

3Q Digital Offers Peek At 3Q Facebook Ad Performance By Its Largest Clients
With Facebook set to report its third-quarter earnings Wednesday , digital marketing agency 3Q Digital offered some insight on how the social ...

Gallop Labs hires former Facebook Client Partner as Director of Sales
Gallop Labs , a social marketing and analytics firm, announced that it has hired former Facebook Client Partner Andrew Peebles as the company’s ...

Sydney builder Bill Issa convicted of attacking clients who complained about his work
... to fix up rundown family homes and transform them into something flashy and new. "It will feel like a new home," he promised one client. "It ...

Client’s “Great Thanksgiving Listen” Campaign Featured on Google Homepage
We love when our clients are successful, and StoryCorps and their amazing Thanksgiving Listen campaign being featured on Google’s homepage certainly ...

Client Portals In Clio
Technology columnist Sean Doherty continues his quest to review client portals in practice management software as a service.

Agencies Should Follow Clients' Lead on Diversity
A few weeks ago, PepsiCo's Brad Jakeman called out advertising agencies for not evolving with the times. Most important, he criticized them for ...

When Clients Don’t Pay: Legal Options for Freelancers
It’s a worst case scenario for a freelancer. After spending valuable time and energy completing a project to your client’s exact specifications, ...

Guggenheim Securities' clients - Business Insider Deutschland
The 16-year-old firm has been an adviser on 5 massive transactions in what has been one of the busiest years for mergers and acquisitions on ...

Lawyer defends cop who shot teen 16 times, says client feared for life
The lawyer for the Chicago police officer who fatally shot 17-year-old Laquan McDonald defended his client Friday, saying the officer feared ...

Resources last updated: 12/8/2015 7:09:45 AM