what client-side and server-side events are fired when button X is hit?

Folks,
In a web aspx page, I use a client-side (javascript) button named "Cancel" so when users hit it, if the data they enter is not saved yet, then this client-side button prompts users to save data before the page is closed. I code this client-side button with event "onclick" and thing like <input type=button ... onclick="btnCancelClick();" >
   My question is if users hit the right top corner button X (next to the maximize and minimize buttons also on the top right corner of the aspx web window page), then what client-side (javascript) and server-side (C#) events are fired when button X is hit?

 Thanks in advance.

-1
johnaspnet
4/16/2006 2:48:33 PM
asp.net.client-side 24353 articles. 2 followers. Follow

10 Replies
2100 Views

Similar Articles

[PageSpeed] 34

Hey John!

The event thats fired is called the "onbeforeunload" event in the HTML page, this code should fire when you close your browser.

"... 

<script language="JavaScript">
window.onload = function()
{
	window.onbeforeunload = function()
	{
		alert("sure you want to close?");
	}
}
</script>

 ..."

However, this code also runs when you refresh the browser, so you have to let JavaScript check the X,Y coordinates to determine if the event was called from anywhere near the 'X' button.

Good luck!

0
Eray
4/16/2006 6:20:51 PM
Hi Eray,
 Thanks very much for your reply for client-side. I do not know what event is fired with server-side (C# event handler). If you know, please post it in this topic.
 
0
johnaspnet
4/17/2006 1:49:12 PM

There is no >>event is fired with server-side (C# event handler)<< since it is a client-side event of the DOM/browser.

NC...

0
NC01
4/17/2006 3:31:26 PM
If it is a client side event, then you can please tell me what is it? I tried to use JS event "onunload" but the event handler is always called when the page is firstly loaded and when the page is finishes its loading. This behavior is acceptable when users hit button X of the browser but it is not acceptable when the page finishes its first loading (not post back) on the client side.
0
johnaspnet
12/27/2006 10:21:25 PM

server side : in the global.asax page, the Session_End event will fire when the user session is cleared or removed or when the user closed the web application.

http://builder.com.com/5100-6371-5771721.html

client side : you can handle the onbeforeunload of the body tag event using javascript.

Happy Coding


Haissam Abdul Malak
MCAD.NET
| Blog |
0
Haissam
12/27/2006 11:26:54 PM

johnaspnet:

If it is a client side event, then you can please tell me what is it?

Client-side, the onbeforeunload event is fired AND then the onunload event is fired.

johnaspnet:

I tried to use JS event "onunload" but the event handler is always called when the page is firstly loaded and when the page is finishes its loading. This behavior is acceptable when users hit button X of the browser but it is not acceptable when the page finishes its first loading (not post back) on the client side.

Of course those events will ALWAYS be fired if the page is closed. It is up to you to differentiate when it is a PostBack or not.

An example:

<script language="JavaScript">
var g_isAPostBack = false;

function window::onbeforeunload()
{
 if ( g_isAPostBack == false )
 {
  var closeMessage =
   'You are exiting this page. ' +
   'If you have made changes without saving, your changes will be lost. ' +
   'Are you sure you want to exit?';

  return closeMessage;
 }

 g_isAPostBack = false;
}
</script>

Add to the CodeBehind, PageLoad event handler:
      Page.RegisterOnSubmitStatement("OnSubmitScript", "g_isAPostBack = true;");

NC...

0
NC01
12/28/2006 11:56:23 AM
If users carelessly hit broswer's X button, how do they can have the last chance (like an client-side confirm message dialog open saying "Do you want to save data?") to keep the aspx page open so they can save the input data if they select button "OK" on that js confirm button? If they select "Cancel" from the confirm dialog, then the page will close and the data is not saved.
0
johnaspnet
12/28/2006 10:52:34 PM

Change the OnBeforeUnload event handler to the following and when the Cancel button is pressed, the page will stay opened. That is the only option that you have, as it is a web page.

<script language="JavaScript">
var g_isAPostBack = false;

function window::onbeforeunload()
{
 if ( g_isAPostBack == false )
 {
  var closeMessage =
   'You are exiting this page. ' +
   'If you have made changes without saving, your changes will be lost. ' +
   'Are you sure you want to exit?';

  window.event.returnValue = closeMessage;
 }

 g_isAPostBack = false;
}
</script>

0
NC01
12/30/2006 11:26:45 AM

NC01 is not online. Last active: 12-30-2006, 7:32 AM NC01 ,
Thanks so much. My page now is working in the way I would like. However, this seems to work with IE but not FireFox or NetScape?

0
johnaspnet
12/30/2006 11:36:05 PM

I believe that  window.event.returnValue is an IE only property. Sorry.

NC...

 

0
NC01
12/31/2006 11:12:05 AM
Reply:

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 (Asp.net) 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...

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

How to access Client Side control in server side button click event?
Hi all, I need to access client side control from server side code. For an example <form id="form1" runat="server"> <table> <tr> <td>UserName:</td> <td><input type="text" id="textBoxUserName" /></td> <td><asp:Button ID="buttonShow" runat="server" Text="show" OnClick="buttonShow_Click" /></td> </tr> </table>   </form> I need to access the textBoxUsername in the server side button click event. How to do that? Than...

Firing server side validation & Client side confirm with a single button..
Hi All, I have a "Update" asp button. onclick of the button i need to check the server side validations like:if (!IsValidEmail(ctrlEmailAddress.TextBoxControl.Text.Trim())) {MessageBox.Show("Enter valid email address"); validateCheck = false; } After completion of this type of validations, i need to fire one javascript confirmbox saying "Are you sure you want to update this order?" with "Yes/No" options. All these things needs to be done in a single button click. Can any one help me to acheive this ..requirement?  -HemanthPlease rem...

Need to send a id string from client side to server side and fire a event
Hi EveryoneI'm having a problem with my ajax script. I'm trying to send a  id string from client side to server side and want to fire a server side event. I have no clue how to do this. Can anyone point me in the right direction ? Take a look at the GetWebRequest, PostWebRequest, and OnWebRequestCompleted JavaScript samples in the AJAX documentation. Lambert You can add static page methods to an ASP.NET page and mark them as Web methods. You can then call these methods from script as if they were part of a Web service, but without creating a separate .asmx file. To create Web metho...

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="http://schemas.microsoft.com/intellisense/ie5"> </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...

client side click handler / server-side command event doesn't fire
I am rewriting an old control of mine to be more AJAX-friendly. It is a subclass of Button that disables itself when clicked, so that the user can't, say, double post a credit card payment. I have some javascript code for the prototype including this: _onClick : function(e) { if(this.get_element() && !this.get_element().disabled && this._DisableAfterClick == true) { this.get_element().disabled = true; if (this._DisabledText != null && this._DisabledText.length > 0) { this.get_element().value = this._DisabledText; } } //this.get_element().form.s...

What is Client Side and Server Side?
I am New of ASP.Net What we can and should do client side and Server Side? What uses? Please any one clear my doubt. Thanking YouEndendrum Priyamudan P m R Clientside is basically what a person can see and serverside is where actions get processed. that's kinda simply puyt but thats the deal, you code serverside, and the html and javascript it generates let's the users for example click a button, then serverside you have coded what should happen when a button gets clicked for example turn text red. Then the server sends a new page with red text to the client (clientside...

Client side and server side
We have a application, where we have some validation on the clientside using EnableClientSideValidation. If you don't have fullscreen you can't see some of the error-messages. What we want is to jump to the place on the page where the message is displayed. One problem is that the button is a serverbutton (runat="server"). How can we accomplish this on the clientside using the same button. I have tried to use "onClientClick" and a link something like this:   <A HREF=http://forums.asp.net/AddPost.aspx?ForumID=18#form>form<...

client-side and server-side?
hi, can someone tells me how diff is client side and server side are these two? When I tried to do validation ... I would use Javascript ... which has something like: document.forms[0] ... I think that's client side. My understanding on server side is the "form" ... like u will have <form action=".." method=post> ..... </form> ... so it will send to server ... am I on the right track? Are there any other type of server side examples? Hi, ASP.NET itself is server side. Every piece of code processed is done on a server. What comes out of this is sent ...

Server Side or Client Side
Hi I'm a bit confused about this whole server side / client side thing. Are applets, embeded objects consider client side? If I have a form within my aspx page which connects to a database on the server side what is it considered? If I have some business logic written within a VB file when the client access the functions within that business logic (for example some kind of validation function) does the client browser actually downloads that VB file? Can someone suggest how to differentiate between client side and server side components within a asp.net based website?  Hi, i can&#...

Server-side or Client-side
In general, I'm wondering if there are any criteria to use when choosing between using a client side element or a server side element. For example, if I'm going to put an HTML table on a page, how do I decide whether or not to use a server control?  Should the server side always be chosen or if there is not explicit server side functionality required is it better to opt for a "normal" client side table? Obviously, if there is a need for server side control the question is answered, I'm looking more at more ambiguous situations. Thanks  This is from Micros...

Web resources about - what client-side and server-side events are fired when button X is hit? - asp.net.client-side

Client-side scripting - Wikipedia, the free encyclopedia
... different and changing content depending on user input, environmental conditions (such as the time of day), or other variables. Client-side ...

Senior Search Manager - Client Side!!
... strategy insight for senior IT management - resources to understand and leverage information technology. Senior Search Manager - Client Side ...

Account Manager - Client Side - Previous Agency Experience Welcome!!
Computerworld Australia is the leading source of technology news, analysis and tools for IT decision makers, managers and professionals.

Media Sales Executive - Client Side!!
Technology news and reviews for business and home.

PPC Paid Search Manager - CLIENT SIDE
Defining Technology for Australia's IT Leaders. PPC Paid Search Manager - SEM - **CLIENT SIDE** Sydney CBD Location Client side!! SEM/PPC/Paid ...

How Basecamp Next got to be so damn fast without using much client-side UI
When we started working on Basecamp Next last year, we had much internal debate about whether we should evolve the existing code base or rewrite ...

Seven Tips for Pitching From the Client's Side of the Table
I had a chance to sit on the other side of the pitch table. Here is what I learned.

Client-side coding: How to prevent malicious use?
Applications that run on a user-controlled device cannot be perfectly protected.

The client side
... regarding the professionals you seek to assist. Even better if you possess that understanding yourself, having worked on the client side. I'm ...

Ecommerce traffic being hijacked by client side malware
According to new research 15 to 30 percent of eCommerce site visitors are infected with Client Side Injected Malware (CSIM) that causes them ...

Resources last updated: 12/3/2015 5:18:19 PM