Relative url returned in hyperlink field

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Relative url returned in hyperlink field

    Hi

    In a bound grid view I have the following hyperlink field;

    <asp:HyperLinkF ield
    DataNavigateUrl Fields="FldDire ctions"
    DataNavigateUrl FormatString="{ 0}"
    HeaderText="Dir ections"
    Target="_blank"
    Text="Direction s">
    <HeaderStyle ForeColor="Whit e" />
    </asp:HyperLinkFi eld>

    FldDirections is coming from the underlying source and provides a url such
    as www.mydomain.com. Problem is clicking on this hyperlink brings the url
    relative to were the site is running ie something like
    http://localhost/Folder1/Folder2/www.mydomain.com. How can I just get the
    value retuned by FldDirections i.e. www.mydomain.com?

    Thanks

    Regards


  • Jonathan Wood

    #2
    Re: Relative url returned in hyperlink field

    Is it because you don't have a protocol prefix? Seems like the browser
    doesn't figure out it's a domain.

    What if you try something like this:

    DataNavigateUrl FormatString="h ttp://{0}"

    --
    Jonathan Wood
    SoftCircuits Programming


    "John" <info@nospam.in fovis.co.ukwrot e in message
    news:%23Ebb9IGx IHA.4488@TK2MSF TNGP04.phx.gbl. ..
    Hi
    >
    In a bound grid view I have the following hyperlink field;
    >
    <asp:HyperLinkF ield
    DataNavigateUrl Fields="FldDire ctions"
    DataNavigateUrl FormatString="{ 0}"
    HeaderText="Dir ections"
    Target="_blank"
    Text="Direction s">
    <HeaderStyle ForeColor="Whit e" />
    </asp:HyperLinkFi eld>
    >
    FldDirections is coming from the underlying source and provides a url such
    as www.mydomain.com. Problem is clicking on this hyperlink brings the url
    relative to were the site is running ie something like
    http://localhost/Folder1/Folder2/www.mydomain.com. How can I just get the
    value retuned by FldDirections i.e. www.mydomain.com?
    >
    Thanks
    >
    Regards
    >

    Comment

    • John

      #3
      Re: Relative url returned in hyperlink field

      Thanks. Anyway to make it conditional i.e. if FldDirections returns the url
      with http:// then it is shown as it is and if without http:// then http://
      is appended?

      Thanks again

      Regards

      "Jonathan Wood" <jwood@softcirc uits.comwrote in message
      news:%23dl8T7Hx IHA.4772@TK2MSF TNGP03.phx.gbl. ..
      Is it because you don't have a protocol prefix? Seems like the browser
      doesn't figure out it's a domain.
      >
      What if you try something like this:
      >
      DataNavigateUrl FormatString="h ttp://{0}"
      >
      --
      Jonathan Wood
      SoftCircuits Programming

      >
      "John" <info@nospam.in fovis.co.ukwrot e in message
      news:%23Ebb9IGx IHA.4488@TK2MSF TNGP04.phx.gbl. ..
      >Hi
      >>
      >In a bound grid view I have the following hyperlink field;
      >>
      > <asp:HyperLinkF ield
      > DataNavigateUrl Fields="FldDire ctions"
      > DataNavigateUrl FormatString="{ 0}"
      > HeaderText="Dir ections"
      > Target="_blank"
      > Text="Direction s">
      > <HeaderStyle ForeColor="Whit e" />
      > </asp:HyperLinkFi eld>
      >>
      >FldDirection s is coming from the underlying source and provides a url
      >such as www.mydomain.com. Problem is clicking on this hyperlink brings
      >the url relative to were the site is running ie something like
      >http://localhost/Folder1/Folder2/www.mydomain.com. How can I just get the
      >value retuned by FldDirections i.e. www.mydomain.com?
      >>
      >Thanks
      >>
      >Regards
      >>
      >

      Comment

      • Munna

        #4
        Re: Relative url returned in hyperlink field

        On Jun 2, 3:29 pm, "John" <i...@nospam.in fovis.co.ukwrot e:
        Thanks. Anyway to make it conditional i.e. if FldDirections returns the url
        with http:// then it is shown as it is and if without http:// then http://
        is appended?
        >
        Thanks again
        >
        Regards
        >
        "Jonathan Wood" <jw...@softcirc uits.comwrote in message
        >
        news:%23dl8T7Hx IHA.4772@TK2MSF TNGP03.phx.gbl. ..
        >
        Is it because you don't have a protocol prefix? Seems like the browser
        doesn't figure out it's a domain.
        >
        What if you try something like this:
        >
        DataNavigateUrl FormatString="h ttp://{0}"
        >
        --
        Jonathan Wood
        SoftCircuits Programming
        http://www.softcircuits.com
        >
        "John" <i...@nospam.in fovis.co.ukwrot e in message
        news:%23Ebb9IGx IHA.4488@TK2MSF TNGP04.phx.gbl. ..
        Hi
        >
        In a bound grid view I have the following hyperlink field;
        >
        <asp:HyperLinkF ield
        DataNavigateUrl Fields="FldDire ctions"
        DataNavigateUrl FormatString="{ 0}"
        HeaderText="Dir ections"
        Target="_blank"
        Text="Direction s">
        <HeaderStyle ForeColor="Whit e" />
        </asp:HyperLinkFi eld>
        >
        FldDirections is coming from the underlying source and provides a url
        such aswww.mydomain. com. Problem is clicking on this hyperlink brings
        the url relative to were the site is running ie something like
        >http://localhost/Folder1/Folder2/www.mydomain.com. How can I just get the
        value retuned by FldDirections i.e.www.mydomain.com?
        >
        Thanks
        >
        Regards
        Hi

        best way to modify such issue is on itemdatabound event...
        in item databound use findcontrol method of item and then re-write the
        url property

        Best of luck

        Munna



        Comment

        • Munna

          #5
          Re: Relative url returned in hyperlink field

          Hi
          I forget to mention another easy way...
          add a public method in your aspx page ...
          and pass the item to format the string...

          for example in code behind file add a method like this

          public string GetFormatedURL( object arg)
          {
          string args = arg.ToString();

          if (args.Contains( "http://"))
          return args;
          else
          return "http://" + args;
          }

          and in aspx page use it like

          <asp:TemplateFi eld HeaderText="Url " SortExpression= "value">
          <ItemTemplate >
          <asp:HyperLin k ID="HyperLink1 " runat="server"
          NavigateUrl='<% # GetFormatedURL( Eval("value") ) %>' Target="_blank"
          Text='<%# Eval("value") %>'></asp:HyperLink>
          </ItemTemplate>
          </asp:TemplateFie ld>

          Best of luck

          Munna



          Comment

          Working...