ASP.NET maintain state with client side JavaScript...?

M

Matt Jensen

Howdy all

Hopefully I can explain my problem straightforwardly.

In it's simplest explanation, what I want to do is have a hyperlink that,
when clicked, executes some client side JavaScript and then saves every form
element value and reloads the page (with the 'save' being much the same as
what is achieved by an AutoPostBack="True" attribute on a web/html control).

Actually it doesn't matter which order the JavaScript or 'save' executes in
if that helps.

FYI, the JavaScript hyperlink opens a new window. The new window performs
functionality relevant to the window that opened it, and when finished, I
need the window that opened it to refresh to show the new data, but I don't
want it to lose any values that may have been entered in form elements by
the user.

Maybe the solution is for the hyperlink to open the new window and then
perform a (.NET) postback (in order to save the form element values) in the
background... Is this possible or feasible?

Or can the hyperlink do a postback, then somehow popup the window...

Or can the popup window cause the window that opened it to do a postback via
window-to-window JavaScript (the main question I have though with this
option is will it just post the form back and not execute any button
actions?).

FYI, the main window has some buttons on it, however I don't want any of
their functions executed when the popup is opened, I just want the element
states maintained.

Maybe I should just play, it seems like the solution could more complicated
than what I might find through trial and error though, and I was hoping that
one of you might know the best solution.

Anyway, thanks for any help.
Cheers
Matt
 
K

Karl Seguin

Well, you can simply have an asp:linkbutton which you attach an OnClick
event

myLink.Attributes.Add("onClick", "OpenWindowAndDoSomething();");

this will fire the OpenWindowAndDoSomething(); javascript method, and then
cause a postback

Karl
 
M

Matt Jensen

Excellent thanks Karl!

Only problem I now face is that when the popup window is finished with and
is closed via JavaScript (which also calls the reload method of the page
that opened the popup), I get the common alert that you get when you try to
refresh a posted page:
"The page cannot be refreshed without sending the information. Click Retry
to send the information again, or click Cancel to return to the page you
were trying to view."

Obviously not ideal. I know this is not a JavaScript forum, don't suppose
you have any ideas re this issue?

Thanks a lot
Cheers
Matt
 
M

Matt Jensen

Hmm, I've used window.opener.location.href instead of window.opener.reload()
and it's solved the situation.
I'd better put no-cache settings on the page then I think...

While I'm here, what is the combination of ASP.NET C# lines of code for
no-cache/pragma settings...?

Cheers
Matt
 

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

Top