I want to use a variable declared in my .cs page(C#) as cc to mailto, but dont know how to use. Please help.
In default.aspx.cs page:
var code=cc#test.com;
In default.aspx page:
<asp:HyperLink ID="HyperLink5" runat="server" NavigateUrl="mailto:to#test.com?subject=Hi&cc=code" ToolTip="Submit" Target="_blank">mail</asp:HyperLink>
This is not a good way to do this but you can set the NavigateUrl from code behind.
Try this:
HyperLink5.NavigateUrl="mailto:to#test.com?subject=Hi&cc="+code;
Have you tried embeding code like
<asp:HyperLink ID="HyperLink5" runat="server" NavigateUrl="mailto:to#test.com?subject=Hi&cc="<%=code%> ToolTip="Submit" Target="_blank">mail</asp:HyperLink>
Related
I am having an issue with using the NavigateUrl within a HyperLink asp.net tag.
The navigationUrl works as in go to the page I want it to go, but when I try to get the Query String "n" it gives me <% instead of the number value within the DataBind. Here is the code:
<asp:HyperLink runat="server" NavigateUrl="~/MyWebsite/info.aspx?n='<%#DataBinder.Eval(Conatainer.DataItem, "num")%>' />
Thank you for your help!
Try with:
<asp:HyperLink runat="server" NavigateUrl='<%# String.Format("~/MyWebsite/info.aspx?n={0}", DataBinder.Eval(Container, "DataItem.num").ToString())%>' >Text</asp:HyperLink>
<asp:HyperLink ID="HyperLink5" runat="server" CssClass="RegAgenda"
NavigateUrl='<%#"http://www.mysite.com/store/" &
DataBinder.Eval(Container.DataItem,"DESCRIPTION")& "?ALID=" &
DataBinder.Eval(Container.DataItem,"TransID")%>'
Target="_blank" Text="Info/Buy Now">
</asp:HyperLink>
In the above asp:HyperLink code, I would like to test if the current page has Chuy2 in the path and if so, change the base url to http://www.mysite2.com
how would I do that? I am a PHP guy and don't know ASP.Net.
Something like this should work:
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# string.Format("{0}/{1}?alid={2}", Request.Url.AbsoluteUri.Contains("Chuy2") ? "http://www.mysite2.com" : "http://www.mysite.com/store", Eval("Description"), Eval("TransID")) %>'
rather than try to piece this together in the markup/template, I would build the url in the code behind, or view model and then bind that value. the markup might look like this
NavigateUrl='<%#Eval("Url")%>'
Lets say we have the following in the default.aspx file
<asp:Literal runat="server" Text="<%= TestMethod() %>" />
What needs to be defined in the default.aspx.cs file to make this work?
I tried to add a method called TestMethod to the _Default class which simply returned the string Test, but it didn't seem to work.
Can anyone help?
Thanks,
AJ
Apart from the method being marked public...
i think you could also remove the asp:Literal altogether
example
your code
<p><asp:Literal runat="server" Text="<%= TestMethod() %>" /></p>
could be
<p><%= TestMethod() %></p>
However if you are intent on using the Literal then please rather set it on page load.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.literal.aspx
Regards.
I think you can get the same result by doing this
In your .aspx file
<asp:Literal runat="server" ID="ltr1" />
And in your aspx.cs file
ltr1.text = TestMethod();
This works:
<asp:HyperLink ID="EditGridItemLink" runat="server" NavigateUrl="<%# GetCustomUrl() %>">
link
</asp:HyperLink>
link value = http://localhost/MyCustomUrl.aspx
This doesn't:
<asp:HyperLink ID="EditGridItemLink" runat="server" NavigateUrl="subfolder/<%# GetCustomUrl() %>">
link
</asp:HyperLink>
link value = http://localhost/subfolder/<%# GetCustomUrl() %>
I'm doing this in a Column/TemplateField of an Asp.NET GridView.
Am I doing something wrong or is this simply impossible.
Of course I'm using a workaround now where I set the rest of the NavigateUrl value as well, but I was wondering why this isn't working...
You can do this instead: NavigateUrl='<%# string.Format("subfolder/{0}", GetCustomUrl()) %>'.
Databinding expressions for properties of server controls must be the only thing in the property (no mixing with static text in the way you tried).
You should put the whole expression inside the databinding markup:
<asp:HyperLink ID="EditGridItemLink" runat="server"
NavigateUrl="<%# "subfolder/" + GetCustomUrl() %>">
link
</asp:HyperLink>
I got this code in order to build an url for the link using a querystring from the current page. The problem is.... It doens't work. Any suggestions?
<asp:hyperlink ID="link1" runat="server" NavigateUrl='<%#("Equipamentos.aspx?ID_Cliente=")+Request.QueryString ("ID_Cliente").trim.tostring()%>'>Equipamentos</asp:HyperLink>
Gah, my eyes! Try doing this in code behind instead:
link1.NavigateUrl = "Equipamentos.aspx?ID_Cliente=" & Request.QueryString("ID_Cliente").Trim().ToString()
You have to use "&" instead of "+" because this is VB.NET, not C#.
Your ASP.NET code should look like this:
<asp:HyperLink ID="link1" runat="server" NavigateUrl=''>Equipamentos</asp:HyperLink>
And then add this in code behind:
this.link1.NavigateUrl = string.Format("Equipamentos.aspx?ID_Cliente={0}", Request.QueryString["ID_Cliente"].Trim());
Try this instead :
<asp:hyperlink ID="link1" runat="server"
NavigateUrl='<%= ("Equipamentos.aspx?ID_Cliente=")
+ Request.QueryString("ID_Cliente").Trim().ToString() %>'>
Equipamentos</asp:HyperLink>
The
<%# %>
tags are for directives, such as registering controls. You need a
<%= %>
tag, which is called a code evaluation block.
Something like
<%= (5+5).ToString() %>
is what you need - try your code in there.
You are not going to be able to set the NavigateUrl of the link in this way. Try something like this:
<asp:hyperlink
ID="link1"
runat="server">Equipamentos</asp:HyperLink>
And then in your codebehing or a script tag do this:
link1.NavigateUrl = "Equipamentos.aspx?ID_Cliente="
+ Request.QueryString("ID_Cliente").Trim().ToString();
As I know you can't use "<%= %>" with server controls. So you can:
1. Leave it as a server control and follow Andrew Hare's (or similar) answer.
2. Use client control: "<a />" and "<%= %>" should work.