in my asp.net application, two buttons call a javascript function called refreshView, below is the function refreshView.
function RefreshView() {
__doPostBack('ButtonApply', '')
window.parent.location.href = "dashboardtree.aspx"
}
In IE, this is working correctly, but in firefox and safari the page refreshes (due to the window.parent.location) – but never calls the doPostBack (i was able to tell this using tracepoint and the sub that is called stores values to the database, the values are not being stored as well, sub is never hit). Below is the first line of the sub.
Private Sub ButtonApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonApply.Click
Can anyone see why this would not work? I figured I could always replace the doPostBack with pageMethods and create a new sub/function – but I’d like to complete this the way it currently is. Thank you.
Don’t perform a redirect and postback at the same time in your JavaScript routine. What you should do instead is to redirect after your postback logic has completed. You will only know when it is completed in the Codebehind or if your Javascript received some sort of Asynchronous callback. In its current state, your JavaScript routine has no idea when your Postback will complete.
You are creating a conflict. What you are essentially doing is telling the page to post and at the very same time to redirect somewhere else. In all likelihood, FireFox and Safari probably ignored the
__doPostBack()because of this fact.Here’s what I would do instead:
EDIT
Apologies, I missed the window.parent.
What I would recommend then is to use ajax. In a nutshell, you would use ajax to place a call to a server-side method which would perform your logic (that you currently do in the postback). Upon completion, the client will be notified in a callback when the process has completed (and whether or not it was successful). Upon successful completion, you would perform your redirect.
There are several examples of this on the web, I’ll provide a few for you: