This is a migrated thread and some comments may be shown as answers.

Intercepting clicked or begin navigate events?

4 Answers 51 Views
HTMLPlaceHolder
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 11 Nov 2009, 11:52 AM
Hi,

We are thinking of developing an application in silverlight using the telerik controls - in particular, the HTML placeholder control.

One thing vital to the application is the ability for users to click on particular links on a generated HTML document and for the application to display a window based on what was clicked (but for the browser itself to continue displaying the page).

With a standard web browser control, you can just trigger code off the BeforeNavigate event, check to see if the URL is one generated by the application and cancel the navigation etc.

I see that the HTMLPlaceHolder control has a UrlLoaded event, but I assume this is only triggered after the HTML document has finished loading.  Is this the only event that the control has?

Since the only links the application cares about are generated by the system, they can take any form, so one idea I have is to simply make the links point to non existent anchors on the page.  For example, if the document is test.html, linking to test.html#contentclicked would not cause the page to reload.  I am unsure if this would trigger the UrlLoaded event either though.

Worst case, all the links could reload the page with an argument, but since this would actually trigger reloading of the page it would add lag to the interface and I would prefer to avoid it.

Can anyone shed any light on this issue?

4 Answers, 1 is accepted

Sort by
0
Tihomir Petkov
Telerik team
answered on 16 Nov 2009, 05:19 PM
Hello Martin,

In your case you can make use of the ability to call methods in your Silvrelight application directly from JavaScript code. I implemented a sample project which demonstrates a HTML document displayed in a RadHtmlPlaceholder. The link in the HTML document is wired so that it calls a JavaScript method which in turn gets a reference to the Silverlight application and calls a method in it. I believe this will work in your scenario and there will be no need to listen for navigation-related events. Please take a look at the project I prepared and let me know if it would work in your case. The approach I suggest really isn't complex, although it may sound so from my explanation.

Greetings,
Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Martin
Top achievements
Rank 1
answered on 17 Nov 2009, 09:41 AM
Hi,

I downloaded your sample code and added "using System.Windows;" to the includes and "MessageBox.Show("Hello!");" to the body of the "TestMethod" function that I believe should be called when you click on the link, however, when I test the project and click the link nothing seems to happen.

Do you have any example code I can put into the TestMethod event to verify that the technique does work?

I'm sorry, I'm rather new to silverlight development so I may well be doing something wrong when attempting to display the message.

I attempted to put the message box in the MainPage() function where the the scriptable object is registered, but nothing happens there either.  I'm not sure if this is an issue with the code or what to be honest.

Thanks,
0
Tihomir Petkov
Telerik team
answered on 17 Nov 2009, 09:57 AM
Hi Martin,

To make sure the code works you can simply place a breakpoint in the method and see if it's hit when you click the link. Alternatively, if you want to display a popup alert, keeping in mind your application is running in a browser, you can use the following method:

HtmlPage.Window.Alert("link clicked!");

Please try the above suggestions and let me know how it goes.

Sincerely yours,
Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Martin
Top achievements
Rank 1
answered on 17 Nov 2009, 10:06 AM
Ah fantastic, I fixed it - I knew it was something stupid and after a brief glance at a silverlight tutorial I realised I needed to hit the "Build" button after adding my message box code.

Thanks for your help, it seems very likely that we will be buying your controls for use in our application!
Tags
HTMLPlaceHolder
Asked by
Martin
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
Martin
Top achievements
Rank 1
Share this question
or