Intercepting clicked or begin navigate events?

5 posts, 0 answers
  1. Martin
    Martin avatar
    10 posts
    Member since:
    Nov 2009

    Posted 11 Nov 2009 Link to this post

    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?
  2. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 16 Nov 2009 Link to this post

    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.
  3. DevCraft banner
  4. Martin
    Martin avatar
    10 posts
    Member since:
    Nov 2009

    Posted 17 Nov 2009 Link to this post

    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,
  5. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 17 Nov 2009 Link to this post

    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.
  6. Martin
    Martin avatar
    10 posts
    Member since:
    Nov 2009

    Posted 17 Nov 2009 Link to this post

    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!
Back to Top
DevCraft banner