Dynamic PostBackUrl from JavaScript

I have a ASP.NET page that is updated dynamically via WebServices and JavaScript. There is a LinkButton that needs to go to 1 of 2 pages depending on the state of the page when it is clicked. This is contained in a MasterPage with hidden fields that need to be maintained so It needs to do a PostBack. How do I either change the PostBackUrl of the LinkButton each time a WebService updates the page or determine which page to redirect to when the button is clicked?
DerekWatlingAsked:
Who is Participating?
 
Refael AckermannCommented:
I believe the best result is to use JavaScript:
  1. Set the link button to have only OnClientClick="Navigate(); return false;" and no OnClick so there will not be any postback.
  2. Use the following JavaScript function code, and setup your parameters (hidden-field name, value, and pages' URLs)
function Navigate()
{
  var hiddenField1 = document.getElementById("<%= hiddenField1.ClientID %>");
  if (hiddenField1.value == "Something")
    location.href = "Page1.aspx";
  else
    location.href = "Page2.aspx";
}

Open in new window

0
 
DerekWatlingAuthor Commented:
This works for redirecting, but I need a Cross Page PostBack as I am using HiddenFields on the MasterPage to track session variables.

After trying various other things I have decided the easiest is to have 2 Image buttons on the page each with a static PostBackUrl and set the display property on the client so that only the relevant button is displayed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.