Hyperlink and ResolveURL

T

tshad

I am finally getting the path to the Current Page using Page.ResolveURL.

I am now getting "/jobSeeker/displayCompanyOverview.aspx" which is what I
was looking for.

But what is the syntax to add it into the HyperLink object?

I tried:

<asp:Hyperlink ID="test2" Text="HyperLink Test with ResolveURL"
NavigateUrl='<%= Page.ResolveUrl("displayCompanyOverview.aspx") %>'
runat="server"/><br>

and this gives me:

http://www.stw.com/applicant/<%=%20Page.ResolveUrl("displayCompanyOverview.aspx")%20%>

I also tried <% %> and had the same problem? Do I need sometype of Eval
syntax?

Thanks,

Tom
 
T

tshad

Tom,
Use <%# ... %> instead of <%= %>

I tried that here:

<asp:Hyperlink ID="test2" Text="HyperLink Test with ResolveURL"
NavigateUrl='<%# Page.ResolveUrl("displayCompanyOverview.aspx") %>'
runat="server"/>

But I am getting just plane text and it is not a link.

Am I missing something?

Thanks,

Tom
 
T

tshad

I can set the NavigateURL for my Hyperlinks programmatically. For example,
I can do the following in the Page_Load event and it works fine:

test3.NavigateURL = Page.ResolveUrl("displayCompanyOverview.aspx")

This sets it fine.

But then for all my pages I will have to either set this for all the
Hyperlinks and HyperlinkColumns in my DataGrid. The former would have to be
set in Page_Load event and the later (datagrids) would have to be set in the
PreRender event (I think). What I was hoping to do was do it in the tag
itself.

Thanks,

Tom
 
T

teemu.keiski

Did you realize you need to call DataBind() for thge Page or the
control in question for databinding expressions <%# %> to be
evaluated?

Teemu
 
T

tshad

Did you realize you need to call DataBind() for thge Page or the
control in question for databinding expressions <%# %> to be
evaluated?

I was pretty sure of that and that was why I also tried <%= and <% neither
of which worked.

Is it possible you can't do this particular function inline?

Thanks,

Tom

Teemu
 
T

tshad

I assume this can't be done.

I was told by some else:

"What you'll need to do then is to use the '<%# %>' data-binding expression
instead, and call Page.DataBind from the code-behind. But if you don't have
code-behind, then I don't believe you can accomplish what you want."

Since I am not using code-behind I assume this can't be done. I have tried
all kinds of combinations and can't get it to work, so I give up as it is
causing too much time.

Thanks,

Tom
 
T

tshad

I decided to try one more time to use the HyperLink in my Datagrid using <%#
%> and eval and unlike a Hyperlink which outside of the datagrid gives me
nothing, this does resolve the path but doesn't do it the same as when you
do it programmatically.

If I do:

dim test as String
test = Page.ResolveUrl("displayCompanyOverview.aspx")
test3.NavigateURL = Page.ResolveUrl("displayCompanyOverview.aspx")

This works fine and gives you the URL:

/jobseeker/displayCompanyOverview.aspx (the Current Page Path)

If I do:

<asp:HyperLinkColumn ItemStyle-Width="190" DataTextField="JobTitle"
DataTextFormatString="{0}" DataNavigateUrlField="PositionID"
DataNavigateUrlFormatString='<%#
Page.ResolveURL("displayPositionNS.aspx?PositionID=" + eval("{0}"))'

This gives me:

/applicant/displayPositionNS.aspx?PositionID=210 (The Controls Path

I have no idea why this is working this way. It makes no sense to me.

It doesn't appear to be using the ResolveURL at all. If it did, it would
resolve to the same path as when it was done programatically.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top