Answered by:
ASP Hyperlink issue

Question
-
User836838134 posted
<asp:hyperlink navigateurl="<%# Eval("Link") %>" text="<%# DataBinder.Eval(Container.DataItem, "VenueName")%>" runat="server" target="_blank" id="lnk">Hi all,</asp:hyperlink>
<asp:hyperlink navigateurl="<%# Eval("Link") %>" text="<%# DataBinder.Eval(Container.DataItem, "VenueName")%>" runat="server" target="_blank">I am helping my daughter build an asp.net website that has an Access database. We are using a DataList with a couple fields inside the ItemTemplate. The one that is giving me trouble is the Hyperlink. The code is below. When the page loads the hyperlink renders like this:</asp:hyperlink>
<asp:hyperlink navigateurl="<%# Eval("Link") %>" text="<%# DataBinder.Eval(Container.DataItem, "VenueName")%>" runat="server" target="_blank"> <a id="ContentPlaceHolder1_DataList1_lnk_6" href="#http://www.washingtonfaire.com/#" target="_blank">Washington Midsummer Renaissance Faire</a>
</asp:hyperlink><asp:hyperlink navigateurl="<%# Eval("Link") %>" text="<%# DataBinder.Eval(Container.DataItem, "VenueName")%>" runat="server" target="_blank">But when I click on the link, it tries to navigate to"</asp:hyperlink><asp:hyperlink navigateurl="<%# Eval("Link") %>" text="<%# DataBinder.Eval(Container.DataItem, "VenueName")%>" runat="server" target="_blank">http://localhost:1852/BOOMPiratesB/Raids.aspx#http://www.washingtonfaire.com/#</asp:hyperlink>
<asp:hyperlink navigateurl="<%# Eval("Link") %>" text="<%# DataBinder.Eval(Container.DataItem, "VenueName")%>" runat="server" target="_blank"></asp:hyperlink> What are we doing wrong?
<asp:hyperlink navigateurl="<%# Eval("Link") %>" text="<%# DataBinder.Eval(Container.DataItem, "VenueName")%>" runat="server" target="_blank"></asp:hyperlink>
<asp:DataList ID="DataList1" runat="server" DataSourceID="AccessDataSource1"> <ItemTemplate> <asp:HyperLink id="lnk" runat="server" NavigateUrl='<%# Eval("Link") %>' Target="_blank" Text='<%# DataBinder.Eval(Container.DataItem, "VenueName")%>'> </asp:HyperLink> <br /> <asp:Label ID="DateTextLabel" runat="server" Text='<%# Eval("DateText") %>' /> <br /> <asp:Label ID="CityStateLabel" runat="server" Text='<%# Eval("CityState") %>' /> <br /> <br /> </ItemTemplate> </asp:DataList> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/my.mdb" SelectCommand="SELECT [VenueName], [Link], [DateText], [Season], [DateStart], [CityState] FROM [qpgRaid]"> </asp:AccessDataSource>
<asp:hyperlink navigateurl="<%# Eval("Link") %>" text="<%# DataBinder.Eval(Container.DataItem, "VenueName")%>" runat="server" target="_blank"></asp:hyperlink> I tried this too.
<asp:HyperLink id="lnk" runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "Link")%>' Target="_blank" Text='<%# DataBinder.Eval(Container.DataItem, "VenueName")%>'> </asp:HyperLink>
Thanks for any insight.
Rhonda
Tuesday, March 29, 2011 11:12 PM
Answers
-
User-821857111 posted
Is the datatype of the column which the link is stored in a Hyperlink field? If so, change it to a Text field. The Hyperlink field is only for use within Access as an application - not as a database for the backend of a web site.
When you change it to a text field, you will notice the octothorpes (# signs) become visible. Run a query against the table to remove them:
UPDATE MyTable SET MyLinkField = Replace([MyLinkField],"#","");
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 6, 2011 10:00 AM
All replies
-
User1030681450 posted
href="#http://www.washingtonfaire.com/#"
The extra "#" at the start of the navigate url is the problem, please check how the link is stored in access data base.
It seems the value in the database is corrupted with an extra #.
Wednesday, March 30, 2011 1:06 AM -
User836838134 posted
It doesn't appear to have any #s in the field in the db.
Rhonda
Tuesday, April 5, 2011 9:34 PM -
User3866881 posted
This problem usually happens because in ASP.NET, if you just import a relate URL, it will follow the local Address URL of the website itself. So I suggest you should save the absolute address URL in the db, and you can just directly do binding: (your address looks like http://……/abc.aspx)
Tuesday, April 5, 2011 10:11 PM -
User-821857111 posted
Is the datatype of the column which the link is stored in a Hyperlink field? If so, change it to a Text field. The Hyperlink field is only for use within Access as an application - not as a database for the backend of a web site.
When you change it to a text field, you will notice the octothorpes (# signs) become visible. Run a query against the table to remove them:
UPDATE MyTable SET MyLinkField = Replace([MyLinkField],"#","");
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 6, 2011 10:00 AM -
User-1199946673 posted
When you change it to a text field, you will notice the octothorpes (# signs) become visibleI never used hyperlink fields, so this is new to me. So I'm still learning ;-)
Run a query against the table to remove them:
UPDATE MyTable SET MyLinkField = Replace([MyLinkField],"#","");
Note that you should run this query in Access and not in ASP.NET, because the Replace function only works in Access, but not in Jet!
Thursday, April 7, 2011 3:21 PM -
User-821857111 posted
When you change it to a text field, you will notice the octothorpes (# signs) become visibleI never used hyperlink fields, so this is new to me. So I'm still learning ;-)
So am I. I guessed what was happening from the initial post, but had to create a hyperlink field in an Access database and change it to Text to confirm my theory. So I didn't "know" this for a fact until yesterday...
Thursday, April 7, 2011 3:50 PM