What I needed to do was pop-up a confirm box, when the user navigated using a header, if the user clicked 'OK', I needed to save any changes (on the server) then redirect to the appropriate page.
I accomplished this by adding an asp:LinkButton for every header link in a <td style="display:none"> I wrote an onclick server event handler for each linkbutton.
Next, in PageLoad, I changed the href attribute for the header links, to run a confirm script, and if the confirm returns true, I run a postback for the appropriate hidden linkbutton, which handles the save and redirect.
Here is the line:
CType(myHeader.FindControl("HomeLink"), HyperLink).Attributes.Item("href") = "javascript:if(confirm('Would you like to save?')){__doPostBack('SavePostBackHome','');}else {window.location = 'Home.aspx'};"
Part of the problem here was that I only wanted this confirm box to pop-up a confirm on a couple pages, not for the whole project.
I've always thought it would be nice to be able to decide what server side function to call from a client side script - I think that is what I found here.
If there is an easier way to use this __doPostBack function, then this post might be a waste of time. What I found is that for some of the ASP controls, the compiler doesn't generate any __doPostBack code, which may make the HyperLink and LinkButton unique.
This same functionality may be possible by changing a variable then resubmitting the form/page and deciding what to do in PageLoad
|