I added HyperLink control in my page. When I enter "http://www.google.com", It is opening in new window (good) and pointing google.
1. When I enter "www.google.com", It is opening in new window, but Url is "http://mysite.com/www.google.com". Why this is happing? How to should point to www.google.com
<a href= '<%# Eval("ConferenceUrl") %>' runat ="server" id="ConferenceUrl"
target="_blank"> <%# Eval("ConferenceUrl")%> </a>
You need http:// in the url, I believe.
The <%# Eval("ConferenceUrl") %> needs to have the http:// prefix. Either change your data or add it to the href attribute.
<%# Eval("ConferenceUrl")%>
you have to add http:// in the beginning of href
Related
I have an .aspx in which there is one anchor tag whose href property is set by the server side code i.e. DataTable.
My site url is : [xxx/Pages/Home.aspx] and suppose the href from the DataTable is bound http://www.google.com then the link redirects to [xxx/Pages/http//www.google.com] instead of http://www.google.com . Somehow it prefixes relative url of page.
My ascx file is :
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<asp:ListView ID="Feed" runat="server">
<ItemTemplate>
<div class="Main">
<div class="Ttile">
<a href="<%# Eval("Link") %>" target="_blank" title="<%# Eval("Title") %>" ><%# Eval("Title") %></a>
</div>
</td>
</tr>
</table>
I want to redirect the user to http://www.google.com when user clicks on the link but the anchor tag redirects to http://xxx/Pages/http//www.google.com
If I put <%# Eval("Link") %> outside the anchor tag then it displays the proper url like : http://www.google.com. It means the data in "Link" column is perfect
How should I tackle this issue?
try this one
<%# RemoveServerUri(Convert.ToString(DataBinder.Eval(Container.DataItem, "Link")))
C#
public string RemoveServerUri(string link)
{
link = link.Replace("xxx/Pages/", "");
return link;
}
I have stored file in my server, clients can download files via my page Home.aspx by clicking on an anchor, but i want to edit the original filename before launching download. How can i do it using an ASP.NET HttpHandler. Thanks in advance.
This is my anchor code:
<% if (document.Path != null) { %>
<a id="downloadLink" runat="server" style="margin: 5px" href="<%# CONTENT_DIRECTORY_ROOT + document.Path %>">
<%= LanguageManager.GetValue("LABEL_DOWNLOAD") %></a>
<% } %>
Try the RewritePath(newUrl) method
HttpContext.Current.RewritePath(sUrl)
Or you could use
HttpContext.Current.Server.Transfer(sUrl)
When I try to append the image name onto the end of the <%$ Resources:LocalizedText, MyKey %> the server doesn't build the path at all.
This is what I'm doing and it's not working:
<img id="Img2" runat="server" src="<%$ Resources:LocalizedText, ImagesPath %>feature_LED.jpg" />
Is there any way to append?
this will work instead
src="<%= Resources.LocalizedText.ImagePath %>
I've tried both snippets below. Nothing. I've tried <%#, <%=, and <%. Nothing. So I'm stuck.
<div style="background-color:Gray; color:white; text-align:center; width:100%;">
<asp:HyperLink ID="HyperLink1" Target="_blank" NavigateUrl='<%= Server.HtmlEncode(String.Format("~/ShowHistory.aspx?section={0}&jobnumber={1}", "APQP Header", "101244")) %>' runat="server">Show Updated History</asp:HyperLink>
<asp:HyperLink Target="_blank" NavigateUrl="~/ShowDeletedHistory.aspx" ID="HyperLink2" runat="server">Show Deleted History</asp:HyperLink></div>
<br />
<div style="background-color:Gray; color:white; text-align:center; width:100%;">
<asp:HyperLink ID="HyperLink1" Target="_blank" NavigateUrl='<%= String.Format("~/ShowHistory.aspx?section={0}&jobnumber={1}", "APQP Header", "101244") %>' runat="server">Show Updated History</asp:HyperLink>
<asp:HyperLink Target="_blank" NavigateUrl="~/ShowDeletedHistory.aspx" ID="HyperLink2" runat="server">Show Deleted History</asp:HyperLink></div>
<br />
Try <%# ... %> and call this.DataBind() (or Me.DataBind()) when your page loads.
Server controls cannot contain this type of tags. The reason is that "<%= %>" is basically equal to Response.Write, which itself executes after the page has gone through its lifecycle, when the response is already constructed. If you use it when setting a value of a server-side control property, this value has to be resolved when (or a little after) parsing the page markup. This is the reason you cannot use "<%= %>" in a server control.
If it was a normal html tag, it would work, but the virtual URL would not.
Is there a reason you're not setting the NavigationUrl in code? It would look much nicer to me.
I have a strange problem with the page I'm designing. I have a link like this:
<a id="asel1" runat="server" href="#"><img id="isel1" runat="server" src="/Images/selbar/1.jpg" /></a>
And when I view source on the resulting page I get this:
<img src="/Images/selbar/1.jpg" id="ctl00_ContentMainSection_CardsControl1_isel1" />
My goal was to programmatically insert a link if it was applicable to the page in question, and leave a href="#" if it wasn't (basically a blank anchor tag). However now it will take them to an actual link, which of course doesn't exist.
How can I make it stop doing this?
How are you inserting the link? I've just tried the following:
<a id="asel1" runat="server" href="#">
<img id="isel1" runat="server" src="/Images/selbar/1.jpg" />
</a>
If you do nothing in the code behind the link is rendered as:
<a href="#" id="ctl00_MainContent_asel1">
<img src="/Images/selbar/1.jpg" id="ctl00_MainContent_isel1" />
</a>
and if in the Page_Load you define the href:
protected void Page_Load(object sender, EventArgs e)
{
asel1.HRef = "../Cards";
}
it will render as:
<a href="../Cards" id="ctl00_MainContent_asel1">
<img src="/Images/selbar/1.jpg" id="ctl00_MainContent_isel1" />
</a>
which other the id mangling is the expected behavior.
I know this is an old question, but I too ran into the exact same problem. In my case the anchor tag was also inside an ASCX file (user control). I found that if I removed:
runat="server"
then the problem was fixed.
I would have replaced the href as following:
<a id="asel1" runat="server" onclick="return false;">
<img id="isel1" runat="server" src="/Images/selbar/1.jpg" />
</a>
You are inserting the link dynamically in asp c#, right?
you have to look there for the href and id.
in asp, Control.ClientID value is generated by concatenating the ID value of the control and the UniqueID value of its parent control. That explains how your id is changing.
According to this Each part of the generated ID property is separated by the ClientIDSeparator property value. The value always returns an underscore (_).
That is why you have id="ctl00_ContentMainSection_CardsControl1_asel1"