Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Firing .NET button click from javascript

$
0
0

I am trying to implement some code that will trigger a .net button click event from Javascript, but it does not work.

Here is my code: 

//isDirty  Javascript CODE
        window.onbeforeunload = function checkSave() {
            alert("checksave");
            var sSave;
            if (isDirty == 1) {
                sSave = window.confirm("Click OK to save now, or Cancel to discard your changes.");
                if (sSave == true) {

                    if (document.getElementById("<% =cmdSave.ClientID%>") != null) {
                        //Fire cmdSave.Click .net event
                        __doPostBack("<%= Page.ClientScript.GetPostBackEventReference(cmdSave, "")%>", "");
                    }

                } else {
                    //Allow user to leave page

                }
            }
        }



And this is the error I receive when I execute it:

The state information is invalid for this page and might be corrupted.

Stack trace:
at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
at System.Web.UI.HiddenFieldPageStatePersister.Load()
at System.Web.UI.Page.LoadPageStateFromPersistenceMedium()
at System.Web.UI.Page.LoadAllState()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.mws_mws_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Can anyone help point out where I'm going wrong? 

Thank you!


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>