Note that there are some explanatory texts on larger screens.

plurals
  1. POCall ASP.NET 2.0 Server side code from Javascript
    primarykey
    data
    text
    <p>I'm struggling with this for the past 3 days. I need to call asp.net serverside code from Javascript when the user closes the browser. I'm using the following code to accomplish this. In my asp.net form I have various validation controls. Even if there are some validation errors, When I close the form the server side code works perfectly in my development box(windows 7). But the same code doesnt work in my production environment(windows server).</p> <p>Does it have something to do with the Validation summary or Validation controls. The button control has Causes validation set to false. So even if there is a validation error still my form will post back. Am I correct? I suspect the form is not getting post back to the server when there is a validation error. But i'm disabling all the validation controls in the javascript before calling the button click event. Can someone throw some light on this issue. </p> <p>There are few blogs which suggests to use JQUERY, AJAX (Pagemethods and script manager). </p> <pre><code> function ConfirmClose(e) { var evtobj = window.event ? event : e; if (evtobj == e) { //firefox if (!evtobj.clientY) { evtobj.returnValue = message; } } else { //IE if (evtobj.clientY &lt; 0) { DisablePageValidators(); document.getElementById('&lt;%# buttonBrowserCloseClick.ClientID %&gt;').click(); } } } function DisablePageValidators() { if ((typeof (Page_Validators) != "undefined") &amp;&amp; (Page_Validators != null)) { var i; for (i = 0; i &lt; Page_Validators.length; i++) { ValidatorEnable(Page_Validators[i], false); } } } //HTML &lt;div style="display:none" &gt; &lt;asp:Button ID="buttonBrowserCloseClick" runat="server" onclick="buttonBrowserCloseClick_Click" Text="Button" Width="141px" CausesValidation="False" /&gt; //Server Code protected void buttonBrowserCloseClick_Click(object sender, EventArgs e) { //Some C# code goes here } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload