Navigate to a new page without putting current page on back stack? - windows-phone-7

In an Windows Phone 7 application I got a CurrentPage, which, on a special event does navigate to a new page using the NavigationService:
NavigationService.Navigate(new Uri("/NewPage.xaml", UriKind.Relative));
Now when the user clicks back on the NewPage I want the app to skip the CurrentPage and go directly to the MainPage of the app.
I tried to use NavigationService.RemoveBackEntry, but this removes the MainPage instead of the CurrentPage.
How do I navigate to a new page without putting the current on the back stack?

When navigating to the NewPage.xaml pass along a parameter so you know when to remove the previous page from the backstack.
You can do this as such:
When navigating from CurrentPage.xaml to NewPage.xaml pass along parameter
bool remove = true;
String removeParam = remove ? bool.TrueString : bool.FalseString;
NavigationService.Navigate(new Uri("/NewPage.xaml?removePrevious="+removeParam , UriKind.Relative));
In the OnNavigatedTo event of NewPage.xaml, check whether to remove the previous page or not.
bool remove = false;
if (NavigationContext.QueryString.ContainsKey("removePrevious"))
{
remove = ((string)NavigationContext.QueryString["removePrevious"]).Equals(bool.TrueString);
NavigationContext.QueryString.Remove("removePrevious");
}
if(remove)
{
NavigationService.RemoveBackEntry();
}
This way, you can decide on the CurrentPage.xaml if you want to remove it from the backstack.

Where do you have called "NavigationService.RemoveBackEntry()"?
I think you have to do it at the new page, not at the page you want to skip!
edit:
So to get a better picture: you are having mainpage -> 1rst sub Page (should be skipped at back navigation) -> 2nd sub page which is independed from 1rst sub page.
2 ideas:
1) Try to call "NavigationService.RemoveBackEntry()" in the OnNavigatedFrom-Event of the 1rst sub page
2) Check in the OnNavigatedTo-Event of the 1rst sub page if the NavigationMode (see event args) == Back and navigate back once more.

It sounds like your calling RemoveBackEntry to early (While you're still on CurrentPage.xaml). Thats why its removing MainPage.xaml. When you navigate to NewPage.xaml, in the OnNavigatedTo event call NavigationService.RemoveBackEntry and that should fix the problem.

Related

How to redirect to another page from within Xamarin Webviews Navigating event

I want to do a very simple thing: if a person goes to a specific page within my webview I want them to be redirected to a different page. I want to do this to prevent an errorpage from showing on session timeout. So this needs to happen from within Xamarin because I have to resend the user credentials.
To do that, I believe I have to catch the Navigating event, check if the webpage corresponds with the page I don't want to see. Cancel the Navigating event and set the browser URL to the page I want to redirect to.
private void Navigating(object sender, WebNavigatingEventArgs e)
{
String url = e.Url;
if (url.Contains("unauthenticated.xhtml"))
{
url = getURL();
e.Cancel = true;
browser.Source = url;
} else
{
e.Cancel = false;
}
LogService.log("navigating to " + url);
}
This doesn't work. I still get to see the ugly unauthenticated.xhtml page and no redirect. If I debug I run through the code correctly so I know the event is always caught well and the check for the website works. If I got to the new url in the browser the correct page is displayed.
Now, if I remove this line
e.Cancel = true;
I get closer to the result I want. Then I do get redirected to unauthenticated.xhtml, but within a second I am redirected again towards the correct page. So the warning flashes on the screen and disappears. (Makes sense: both Navigation events still go through)
I have also tried placing these two lines in this order:
browser.Source = url;
e.Cancel = true;
But the result didn't change.
How can I get a well working redirection from within the program?
Thank you for your help.

Nativescript Get Current Page

How can I get the current screen I'm working on? For example, I have a slidedrawer containing buttons to navigate to another page. When I'm on a certain page(About Page) and when I tap the button to navigate to the About Page, I want to just close the slidedrawer if it is on the same page.
My idea is that to get the current page and just compare it but I dont know how.
Note: The slidedrawer content menu is a custom component.
There are several ways to solve this problem. The easiest is to install the nativescript-dom plugin and then you can do this really simply:
// This will return an array of elements that are SlideDrawer's.
var slideDrawers = getElementsByTagName('SlideDrawer');
or even better is if you have assigned your SlideDrawer an id, you can do
<!-- Declarative XML -->
<SlideDrawer id="myId">...</SlideDrawer>
// JS: Will return a single element that matching the id.
var mySlideDrawer = getElementById('myId');
However, if you just want to not use any helpers and you want to get direct access to the currentPage the method is to do:
var frame = require('ui/frame');
var myPage = frame.topmost().currentPage;
Please note; the currentPage will reflect the old page while navigation is taking effect until the navigatedTo event is fired, at that point the currentPage is actually updated to be the currentPage. However, if you are looking for the current page during any of the navigation events (NavigatingTo, NavigatedTo, Loaded, Unloaded) each of those events are transferred a parameter with the current page as part of the object.
exports.onNavigatedTo = function(args) {
var page = args.object;
// do what you want with the current page variable
}

Change the visible sate of a link button inside a datalist

I want to change the visible state and enable state of a link button inside a data list when another button in the same data list is clicked.How can I do that?
Here is the code:
if (e.CommandName == "Save")
{
DataListItem item = (DataListItem)(((LinkButton)(e.CommandSource)).NamingContainer);
LinkButton lnk=(LinkButton)item.FindControl("LinkButton2");
lnk.Visible=false;
}
This code is not working
Hello I am a bit late in answering this but for Linkbutton to change its visible state by using display:none
lnk.Attributes.Add("style", "display:none");

Wicket Panel not refreshed when swapped in via an AJAX request

I have a Panel that I initially replace with another panel (a spinning circle saying "loading") and after a while in an AJAX event replace back. So what I do is:
#Override
protected void onConfigure() {
if (!content.isLoaded()) {
tmp = new LoadingCircle(getId(), "Loading...");
this.replaceWith(tmp);
}
}
public void onLoaded(AjaxRequestTarget target) {
if (tmp != null) {
tmp.replaceWith(this);
tmp = null;
}
target.add(this);
}
This works, so the panel is shown back in the page. However, this panel has some subpanels with some labels and they are not refreshed. I see the updated labels when I reload the page but not immediately after showing the whole panel with AJAX.
I notice that the onConfigure and onBeforeRender methods are called only once - when the panel is created but not again when it is actually shown for the first time using AJAX. The same for the subpanels, so that would explain why they are not refreshed. But the question is - why is the panel not refreshed (the updated model values are not used) when it is added to the AJAX request target?
EDIT: I think this may be relevant: https://issues.apache.org/jira/browse/WICKET-5107. Still, I wonder what I should change in my code to make it work?
IMO it looks like you should use an AjaxCallDecorator instead to do what you are trying to do with the spinner.

DOMContentLoaded events stops getting triggered. Why?

Well, I'm developing a firefox addon that reload a given set of url automatically with some modification. Its not possible to show the whole code. So, I've just copy paste the part of the code which is giving me the error.
The DOMContentLoaded event is suppose to be triggered everything a page is loaded, and it do it properly. The problem is that, if i open a new tab, then DOMContentLoaded event is not triggered in the old tab.
//Any code here runs only for the first time u start the browser
window.addEventListener("load", function() { myExtension.init(); }, false);
var myExtension = {
init: function()
{
var appcontent = document.getElementById("appcontent");
if(appcontent)
appcontent.addEventListener("DOMContentLoaded", myExtension.onPageLoad, true);
},
onPageLoad: function(aEvent)
{
var doc = aEvent.originalTarget; // doc is document triggered "onload" event
//execute on one the top page (not on iframes)
if ((aEvent.originalTarget.nodeName == '#document') && (aEvent.originalTarget.defaultView.location.href == gBrowser.currentURI.spec))
{setTimeout(function(){showInError(doc.location='about:home'}, 500);}
},
}
I'd like to write the problem in a simple way (sorry for my bad English)
1) i run firefox, and the tab (say tab no.1) is continuously reloaded as i want.
2) the tab no.1 page continues to load repeatedly if i leave the page uninterrupted(that's what it want)
3) if i open a new tab (say tab no. 2), the new tab (tab no. 2) begins to reload continuously as i wanted. However, the tab no. 1 stops reloading.
what i want is to to keep on reloading both tab no 1 and tab no. 2. How to do it? what is wrong is my code?
It looks like you are executing the script only on currently displayed page (active tab).
If you want to execute it on other tabs, you should attach event listeners to new tabs as you open them (and don't forget to remove them when you close the tab). You can get useful snippets for this functionality at this page:
https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads#WebProgressListeners
Try using gBrowser instead of document.getElementById("appcontent");
gBrowser.addEventListener("DOMContentLoaded", myExtension.onPageLoad, true);
https://developer.mozilla.org/en/Code_snippets/On_page_load#Basic_onPageLoad_for_a_browser_window

Resources