Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Navigating to another aspx page from an XAML control RSS

18 replies

Last post Aug 04, 2010 09:39 AM by Manekenn

(0)
  • senthilkumarmohan

    senthilkumar...

    Member

    12 Points

    9 Posts

    Navigating to another aspx page from an XAML control

    Jul 11, 2007 07:00 PM | LINK

    Hi All, I have an <asp:xaml> control in an aspx page.

    The xaml control has many child elements like textblock, rectangle..etc.,

    I want to redirect to a different aspx page on click of a TextBlock in the xaml control. How can I do this?

     I am using C# as the language for xaml codebehind.

     Thanks

    Senthil

  • heuertk

    heuertk

    Participant

    1668 Points

    524 Posts

    Microsoft

    Moderator

    Re: Navigating to another aspx page from an XAML control

    Jul 11, 2007 07:24 PM | LINK

    on your TextBlock, you'll want to add an event handler for the MouseLeftButtonUp event handler and do a browers Navigate (using the BrowserHost object).

    -th
    http://timheuer.com/blog/

    -----

    If this answered your question, please be sure to click the 'mark as answered' feature, otherwise please feel free to post follow-up questions that are related.
  • senthilkumarmohan

    senthilkumar...

    Member

    12 Points

    9 Posts

    Re: Re: Navigating to another aspx page from an XAML control

    Jul 11, 2007 07:39 PM | LINK

    I am able to access the BrowserHost class...but unable to see any method with the name.."Navigate"...

    Please correct me if I am wrong...

    Thanks

    Senthil

  • Kevgor

    Kevgor

    Member

    224 Points

    77 Posts

    Re: Re: Navigating to another aspx page from an XAML control

    Jul 11, 2007 08:01 PM | LINK

    Just include System.Windows.Browser namespace and in your code call

    HtmlPage.Navigate(MyURL);

    where MyURL is your target. It's a static method, so you can call it from anywhere

     Kevgor

  • senthilkumarmohan

    senthilkumar...

    Member

    12 Points

    9 Posts

    Re: Re: Re: Navigating to another aspx page from an XAML control

    Jul 11, 2007 08:11 PM | LINK

    Thanks a lot Kevgor.

    It has worked.

    -Senthi

     

  • senthilkumarmohan

    senthilkumar...

    Member

    12 Points

    9 Posts

    Re: Re: Re: Re: Navigating to another aspx page from an XAML control

    Jul 12, 2007 05:47 PM | LINK

    In the above mentioned HtmlPage.Navigate method ...looks like we need to pass absolute URL of the target aspx page.

    Is there any method that accepts relative url.

    Thanks

    Senthil

  • heuertk

    heuertk

    Participant

    1668 Points

    524 Posts

    Microsoft

    Moderator

    Re: Re: Re: Re: Navigating to another aspx page from an XAML control

    Jul 12, 2007 06:22 PM | LINK

    not at my dev machine but, you could simply use some other function to get the current host url and append that to your relative URL string... 

    -th
    http://timheuer.com/blog/

    -----

    If this answered your question, please be sure to click the 'mark as answered' feature, otherwise please feel free to post follow-up questions that are related.
  • Kevgor

    Kevgor

    Member

    224 Points

    77 Posts

    Re: Re: Re: Re: Navigating to another aspx page from an XAML control

    Jul 12, 2007 06:24 PM | LINK

    Yes, a quick test seems to indicate to me that relative URI are not accepted. I think what you might be able to do is

    String relativeURL = "Sample/hello.htm";  // or whatever your relative URl is...

    Uri currentURL = HtmlPage.DocumentUri;

    int idx = currentURL.OriginalString.IndexOf(currentURL.LocalPath);

    string newURL = currentURL.OriginalString.Substring(0, idx + 1) + relativeURL;

    HtmlPage.Navigate(newURL);

    Hope this helps

    Kevgor

  • senthilkumarmohan

    senthilkumar...

    Member

    12 Points

    9 Posts

    Re: Re: Re: Re: Navigating to another aspx page from an XAML control

    Jul 12, 2007 09:13 PM | LINK

    Kevgor, this works if all the pages are at the root level. but, If we have pages in directories..this wont work.

    eg: Say we want to navigate from http://localhost/testsite/test1.aspx to http://localhost/testsite/test2.aspx...

    absolute url: http://localhost/testsite/test1.aspx, In this case, the LocalPath will return testsite/test1.aspx

    appending the target url with the first part.....http://localhost/ will give us....http://localhost/test2.aspx....which is invalid.

     

     Thanks

    Senthil

  • Kevgor

    Kevgor

    Member

    224 Points

    77 Posts

    Re: Navigating to another aspx page from an XAML control

    Jul 13, 2007 12:44 AM | LINK

    Okay, how about this. This works if the root url is of the form:

     http://server:port/vdir/currentpage

    and will produce the new URl (with relative URL properly appended):

     http://server:port/vdir/sample/hello.htm

    // Code 
    String relativeURL = "Sample/hello.htm";
    Uri currentURL = HtmlPage.DocumentUri;
    string[] pathParts = currentURL.LocalPath.Split('/');
    int idx = currentURL.OriginalString.IndexOf(currentURL.LocalPath);
    string newURL = currentURL.OriginalString.Substring(0, idx + 1) + pathParts[1] + "/"+ relativeURL;
    HtmlPage.Navigate(newURL);

    It's still not totally general purpose, but I'm sure you can do additional parsing/composing if you need to...

    Kevgor