doPostBack

M

masoud bayan

Hi ,

I used your suggested code to replace doPostBack in my application, but it
seems window.onbeforeunload is called before, window.__doPostBack, so it can
not change the condition for showing warning message.
I am using datagrid with links as ButtonColumn but I do not want
onbeforeunload event called when they are clicked.

Any suggestion?

Thanks
Masoud



bruce barker said:
1) could be any control thats supports validation on the page (must not be
empty)

2)

air code:

RegisterStartupScript("postback",@"
<script>
if (window.__doPostBack) {
window.__oldPostBack = window.__doPostBack;
window.__doPostBack = function(t, a) {
// add custom code here
window.__oldPostBack(t,a);
}
</script>
");

-- bruce (sqlwork.com)


| Thanks Bruce.
|
| A couple of questions:
|
| 1. I would need to set a custom validator's "control to validate"
| property, right? If so, would that be the DataGrid? The links
| themselves are not controls and they are not available at design time.
|
| 2. How would I replace __doPostBack? I saw a reference to this in
| another post and tried things like oldPostBack = __doPostBack;
| __doPostBack = myPostBack, but this seemed to have not effect. I
| figure those were just interpreted as variable names rather than
| function names, so the functions themselves never changed.
| Thanks again.
|



here are two approaches

1) write a custom validator that sets the flag
2) replace __doPostback with your own routine that sets the flag. note:
submit buttons donot call __doPostback, so you must also catch the postback
in the onsubmit handler.

-- bruce (sqlwork.com




Hi there,

I have an asp.net page with essentially a "don't forget to save" pop-up
that is called when the user attempts to navigate away from the page.
The user has the option to cancel and prevent the page from unloading.

Since the form data is posted back to the server and saved during a
normal postback, I don't need to prompt unless the user is actually
going to a different URL or closing the browser. Currently, I get
around this with a hidden field called hidPromptToSave and by checking
that in my function that onbeforeunload calls. I configured each
control that causes a postback to set that value to false, which causes
the function to exit without prompting.

This worked when I could add the onclick attribute to the controls in
the OnInit method in my code behind. Now, however, I have added a
twist. I added paging to a datagrid and each page link causes a
postback (naturally). Unfortunately, the page links are anchor tags
with an href that calls doPostBack. I can't seem to find a way to add
to the href or onclick attributes of these links. I've tried a whole
lot of things both client-side and server-side.

Assuming I won't ever find a way to add attributes to those links, can
anyone suggest a different way to give a user the chance to save before
closing or navigating away, but not doing this on postpack? One
additional restriction is that we don't want to automatically save
without asking and then let them continue.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top