Navigate back button with ssrs in Silverlight app - silverlight

I have a Silverlight application which has a RadHtmlPlaceholder which points to ssrs to display reports like so:
<telerik:RadHtmlPlaceholder SourceUrl="http://serverName/ReportServer/Pages/ReportViewer.aspx?/Northwind/Employees&rs:Command=render" />
This works fine but when I have a report that allows you to drill down to display a child report, there is no way of getting back to the parent report without having to load the whole lot again. There doesn't seem to be an option to turn on the navigate back button toolbar option and I've seen other ways of implementing a back button by using javascript to set the window location back one in the history, but obviously this won't work in a Silverlight application. Is there anyway to implement a navigate back button?

Take a look at this thread over in the Telerik forums: http://www.telerik.com/community/forums/silverlight/htmlplaceholder/html-place-holder-back-forward-refresh.aspx
Basically you need to get a handle on the IFrame from the presenter and inject some JavaScript. The history object also has a length property you can use to evaluate if your buttons should be enabled.
public MainPage()
{
InitializeComponent();
// Get the IFrame from the HtmlPresenter
HtmlElement iframe = (HtmlElement)htmlPlaceholder.HtmlPresenter.Children[0];
// Set an ID to the IFrame so that can be used later when calling the javascript
iframe.SetAttribute("id", "myIFrame");
}
private void Refresh_Click(object sender, RoutedEventArgs e)
{
// Code to be executed
string code = "document.getElementById('myIFrame').contentWindow.location.reload(true);";
HtmlPage.Window.Eval(code);
}
private void Back_Click(object sender, RoutedEventArgs e)
{
// Code to be executed
string code = "document.getElementById('myIFrame').contentWindow.history.back();";
HtmlPage.Window.Eval(code);
}
private void Forward_Click(object sender, RoutedEventArgs e)
{
// Code to be executed
string code = "document.getElementById('myIFrame').contentWindow.history.forward();";
HtmlPage.Window.Eval(code);
}
}

Related

javascript bounded cant change form object visible false

I changed cefsharp winforms example.
it bound callback.
browser.RegisterJsObject("bound", new BrowserForm());
it bound BrowserForm to can access from java to call AddTab from java
I successfully called c# methods from javascript via bound.
my problem is I cant hide image object when calling from java.
but with button on form we can do.
c# code
public void Load_successfull()
{
MessageBox.Show("working good.");
loading_animation.Visible = false;
}
private void button2_Click(object sender, EventArgs e)
{
Load_successfull();
}
java code:
bound.load_successfull();
when called from java cant hide loading_animation

Wpf webbrowser disable external links

elI am working on a Wpf application. it contains a webbrowser where the user authenticates via Facebook. The problem is that the user is capable of clicking on links (for example: Forgot your password?) the standaard browser then open... what i want to do is to disable/block all the external links. so users can only authenticate and not navigate through the webbrowser control. I hoop you guys can help me out.
Update 1
Like suggested i can check the source of the webbrowser. So i can allow the wanted pages. but the problem are the links. they open on IE. i dont want to open them, but to block them at all
Description image
private void webBrowserFacebook_Navigating_1(object sender, NavigatingCancelEventArgs e)
{
string huidigeLink = Convert.ToString(webBrowserFacebook.Source);
MessageBox.Show(huidigeLink);
// check for allowed pages
}
Update 2
I was able to find a solution: http://social.technet.microsoft.com/wiki/contents/articles/22943.preventing-external-links-from-opening-in-new-window-in-wpf-web-browser.aspx
Very slef explanatory.. thank you guys for the help!
void Window1_Loaded(object sender, RoutedEventArgs e)
{
browser = new WebBrowser();
browser.Navigate(new Uri("http://www.google.com"));
browser.Navigating += new NavigatingCancelEventHandler(browser_Navigating);
browser.Navigated += new NavigatedEventHandler(browser_Navigated);
}
void browser_Navigating(object sender, NavigatingCancelEventArgs e)
{
//Your checks should happen here..
Console.WriteLine("Loading Webpage !!");
}
void browser_Navigated(object sender, NavigationEventArgs e)
{
Console.WriteLine("Webpage Loaded !!");
}
You can register for WebBrowser.Navigating Event.
Navigating event handlers are passed an instance of the NavigatingCancelEventArgs class. You can cancel the navigation by setting the Cancel property of the NavigatingCancelEventArgs object to true.
Or you can invoke script or browser instance to stop loading if URL navigating doesn't matches.
yourWebBrowser.InvokeScript("eval", "document.execCommand('Stop');");

Webbrowser Control - overtyping does not delete selected text when editing HTML [duplicate]

In my C# app I get an xml from a server that contains some replies like in a forum thread (with elements like author, time, body, title, whatever).
When I get this xml, I create a new form in which i want to display these replies, and a little text box with an "add reply" button. I'd also like some edit buttons on perhaps my own replies in the reply list displayed in the form.
The simplest way that came to my mind to display the replies is to put a web browser control in the form, generate a full html page in a string from the xml, and throw it in that web browser control. And under it i can put the text box with the add reply button.
Everything is ok, except that i have no idea of how i could implement the edit function on my own replies (i mean i could add a link in there... but link to what)
I would like to know if there is a way to get that edit event from the web browser control (my guess is i can't) or another (maybe simple/easy) idea of displaying the replies in a winform using other controls
Yes, that's possible, you want to turn "design mode" on for the document. Add a reference to Microsoft.mshtml. Start a new Windows Forms project and drop a WB and a button on the form. Make the code look similar to this:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
webBrowser1.DocumentText = "<html><body><textarea rows='15' cols='92' name='post-text' id='wmd-input'></textarea></body></html>";
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
button1.Click += button1_Click;
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
mshtml.IHTMLDocument2 doc = webBrowser1.ActiveXInstance as mshtml.IHTMLDocument2;
doc.designMode = "On";
}
private void button1_Click(object sender, EventArgs e) {
var html = webBrowser1.Document.Body.All["post-text"].InnerHtml;
// do something with that
//...
}
}

WPF Webbrowser control issue when no internet

I have a Web browser control in my project. Works great! However if I loose connection to the internet then open the project, IE opens and shows the standard cannot display webpage.
I'd prefer the Web browser control in my project show this message and not pop up a IE browser window when the internet connection is lost.
Thanks!
You can do this by importing System.Net.NetworkInformation namespace. NetworkChange Class exposes a event called NetworkAvailabilityChanged which is responsible to notify the application on connection status change. Please find the below snippet. Please mark the answer if useful.
public partial class MainWindow : Window
{
public bool IsAvailable { get; set; }
public MainWindow()
{
InitializeComponent();
NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
}
void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
IsAvailable = e.IsAvailable;
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
if (IsAvailable)
{
WebBrowser1.Navigate(TextBox1.Text);
}
else
{
MessageBox.Show("Your Popup Message");
}
}
}
I don't see IE open on my machine, but I do see the normal IE error messages displaying within the WebBrowser control.
I believe you could detect that the webpage wasn't loaded properly by handling the WebBrowser's Navigated event, and looking at the document's url property. Here is some XAML:
<WebBrowser Source="http://www.google.com" Navigated="WebBrowser_Navigated" />
And a bit of code (I don't do VB, sorry):
private void WebBrowser_Navigated(object sender, NavigationEventArgs e) {
var browser = sender as WebBrowser;
if (browser != null) {
var doc = browser.Document as HTMLDocument;
if (doc != null)
MessageBox.Show(doc.url);
}
}
On my machine, when the navigation failed, I got this URL:
res:ieframe.dll/navcancl.html#http://www.google.com
While I don't think we could count on the URL being exactly this all the time, I bet you could inspect it and determine that it's NOT the URL you were looking for. In fact, the "http:" is now "res:". When you see this happen (and don't expect it) you could make the browser point to a local source to display a message.

WPF - Toggle Visibility of multiple windows

i will first explain the UI of my WPF App.
I have created a window which contains many buttons which is always visible to the user(lets call it main window), each button will open a new window relevant to the task. what i want done is that whenever a button is clicked, the main window should be hidden(visibility : collapsed) and the new window should be shown. This second window will also contain a button which will hide the second window and show back the main window.
also the second window which will be opening will have different dimensions as per the command associated with it so i will be having different windows for eaach
TLDR i want to be able to switch between multiple windows such that only one window is visible at one time, how do i manage the switching between multiple windows ??
Note : I can show the second window from main window but what about showing main from the second window....can't get it....or if anyone can show me a different approach to implement this : other than multiple windows
Also, this is an extension to the UI, i want to show the buttons in this crystalised sort of look like on this page : http://postimage.org/image/4yibiulsh/
can anyone direct me to a proper implementation, i have been through many sites and also tried to create these through blend but i just am not a UI Person....pls need help on this
Thanks in advance.
I would create a "Window manager" which will subscribe to the changes of opening/closing.
In this case you don't have to overload Window classes.
Example (worked for me).
public class WindowsManager
{
static readonly List<Window> Windows=new List<Window>();
public static T CreateWindow<T>(T window) where T:Window
{
Windows.Add(window);
window.Closed += WindowClosed;
window.IsVisibleChanged += WindowIsVisibleChanged;
return window;
}
static void WindowIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var mainWindow = Application.Current.Windows.OfType<MainWindow>().Single();
mainWindow.Visibility = Equals(e.NewValue, true) ? Visibility.Hidden : Visibility.Visible;
}
static void WindowClosed(object sender, System.EventArgs e)
{
var window = (Window) sender;
window.Closed -= WindowClosed;
window.IsVisibleChanged -= WindowIsVisibleChanged;
Windows.Remove(window);
}
}
How to use:
private void button1_Click(object sender, RoutedEventArgs e)
{
WindowsManager.CreateWindow(new Child1()).Show();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
WindowsManager.CreateWindow(new Child2()).Show();
}
So, when the child window will close, WindowsManager will be notified about this and will update visibility for the main window
UPD1.
added line to unscubscribe from VisibleChanged
You can use several approaches for that.
To easy switch back to main Window: inject a reference of your MainWindow to your SecondWindow (or any other Window you want to display) and in the Closing Event of that Window you set the Visibility of the MainWindow back to Visible.
Have you also considered keeping everything in the same Window but having different Panels that you set Visible and Invisible? That could have the same effect but it's less complicated...
Hope that helps...

Resources