• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2744
  • Last Modified:

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?
0
DerekWatling
Asked:
DerekWatling
1 Solution
 
moseackCommented:
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

Featured Post

Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as high-speed processing of the cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now