I'm loading links into a gridview, but if they aren't appended with http:// it goes to my server. So something like www.yahoo.com when clicked would go to http://localhost:1304/.../controls/www.yahoo.com. How would I make the browser open a new window to whatever is in the link field when clicked besides doing string manipulation.
I've tried both asp:hyperlinkfield and templatefields
<asp:TemplateField HeaderText="Link">
<ItemTemplate>
<asp:HyperLink runat="server" Text='<% #(Eval("Link")) %>' NavigateUrl='<% #Eval("Link") %>' />
</ItemTemplate>
</asp:TemplateField>
<%--<asp:HyperLinkField DataTextField="Link" HeaderText="Link" SortExpression="Link" DataNavigateUrlFormatString="{0}" DataNavigateUrlFields="Link" Target="_blank" />--%>
Here is some source from the page. The comcast link appends itself to a local destination while the yahoo one is fine.
<td>15478963</td><td>test data - comcast</td><td>www.comcast.net</td><td align="right">12/23/2009</td><td>Justen</td>
</tr><tr style="color:Black;background-color:Gainsboro;">
<td>12345678</td><td>Update works!</td><td>http://www.yahoo.com</td><td align="right">12/23/2009</td><td>Justen</td>
This behavior (appending the url to the end of your local server) is caused by the way URL's are interpreted by browsers. To redirect to www.yahoo.com, for example, you have to use an absolute URL, starting with http://.
If your links are pointing to addresses which don't start with http://, then the browser interprets them as relative urls, in relation to the present (local server) location.
So you'll have to do some string manipulation, to check whether the address starts with http:// and add it when it's necessary. Maybe you could do it in the OnRowDataBound event handler for the GridView
Also, to make the links open a new window (or tab) in the browser, you should use the target="_blank" attribute, as pointed out in the previous answer.
You need to add a target="_blank" attribute to the link. This will open any link in a new window.
See the href target attribute documentation.
Related
I have added this HyperLink in markup aspx page for open window popup from GridView.
This code working correctly on Google Chrome but is open new webpage on Internet Explorer 11 and not window popup.
In the folder of project I have added the subfolder App_Browsers without success.
How to do resolve this ?
Can you help me?
Thank you in advance, my code below.
<asp:TemplateField HeaderText="btest">
<ItemTemplate>
<asp:HyperLink runat="server" ID="btest" Text="btest"
NavigateUrl='<%# String.Format("btest.aspx?sID={0}", Eval("Sample_ID"))%>'
onclick="javascript:w= window.open(this.href,'Sample_ID',
'left=20,top=20,width=1500,height=300,toolbar=0,resizable=0');return false;">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Opening a page in new window depends on your browser settings.
window.open will have different behaviour in different browser as per browser settings.
if you want to make same behaviour in all browser, use any modal popup like jquery modal or bootstrap modal.
Please find links below.
https://jqueryui.com/dialog/#modal-form
http://getbootstrap.com/javascript/#modals
I'm new to ASP.NET and C# and also new to this forum but here is my problem.
I'm trying to create a image gallery with ASP.NET Webforms(requirement) and C#. I'm using a Listview to show the thumbnails and when you click on the small picture the big version should show above in a img tag for example. But I cant find any "OnClick" code for a hyperlink. Do I have to do that with JavaScript?
Thanks for all help.
here is some of the code:
<ItemTemplate>
<asp:HyperLink ID="ImageHyperLink" runat="server" ImageUrl='<%# Eval("Name","~/files/thumbs/{0}") %>' NavigateUrl='<%# Eval("Name","~/files/{0}") %>'></asp:HyperLink>
</ItemTemplate>
Try taking a look at LinkButton
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton(v=vs.110).aspx
<asp:LinkButton runat="server" id="LinkButton1" OnClick="OnClickAction"></asp:LinkButton>
This will allow you to do a server-side method in much the same way an <asp:Button> will do. However will look just like a hyperlink.
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="http://stackoverflow.com/">HyperLink</asp:HyperLink>
You will not get on click event for HyperLink, But for navigating on to the another page.
You will get one property which is NavigateUrl
By using this property you can redirect to any page by giving url.
I have a datagrid that needs one of the fields to hyperlink to a document housed on another server. The path is in this format: \\server\location\file.doc, but when I click on the cell in the data grid it becomes: http://myASPServer/Subfolder/server/location.file.doc. Is there any way that I can force this to go to the correct location? I know that you can prevent this for external websites by adding ftp:// or http://, but this does not seem to work for opening up this server location. Any suggestions?
I believe your answer can be found here on the asp.net forums http://forums.asp.net/t/1140909.aspx/1 - accepted answer from there below for your convenience.
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink Text="TextField" id="myHL" runat="server"
NavigateUrl='<%# "file:///" + DataBinder.Eval(Container.DataItem, "Path").ToString() %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
I believe you need to prefix your links with file:/// for it would be file:///\\server\location\file.doc
I am totally new to URL Rewriting and WildCard Subdomain management.
My requirement is that I have a gridview in my ASP.Net 3.5 WebApp from where a hyperlinks navigate url property is dynamically generating the following url.
http://businessbazaar.in/BusinessBazaarAspx/Details.aspx?cid=1&name=Steel_Bird_Fabricators
Note : here _ denotes the white space between the words.
Now what I want is that when a user click on the url ,the browser will rewrite the url to
http://steelbirdfabricators.businessbazaar.in
I want it to achieve this via some dll or web.config. I don't want it on IIS as setting, Is this possible? Then please tell me how? It will be highly appreciated.
I'm assuming that somewhere in your gridview you have something like this:
<asp:TemplateField HeaderText="Url">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
Text='<%# Bind("CategoryName") %>'
NavigateUrl='http://businessbazaar.in/BusinessBazaarAspx/Details.aspx?cid=1
&name=<%# Eval("CategoryName") %>' ></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
If you were to change that to something like
<asp:TemplateField HeaderText="Url">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
Text='<%# Bind("CategoryName") %>'
NavigateUrl='http://<%# Eval("CategoryName") %>.businessbazaar.in/' >
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Then that would solve the requested issue.
However this isn't going to deal with the implicit question - which is "How do I dynamically handle subdomains" - which is where your pain is probably going to start:
For this to work in IIS, you'll need a wildcard DNS entry set up, and then a dedicated IP address for the sites in IIS that you can map all these requests on to (it appears that IIS doesn't support wildcard host header entries).
You'll then need to set up something like the UrlRewrite IIS module or similar to handle the requests and work out what it actually needs to send to your application to get the correct information back to the user.
As a point of note, most SEO people will recommend against sub domains for permanent areas of your site as they carry less weight than pages/folders beneath the main domain. So you'd be better off taking the easier option of URLs such as: http://businessbazaar.in/steel-bird-fabricators (Note also the more SEO friendly use of hyphens to separate the words rather than underscores or mashingthemalltogther).
Ive got a asp.net web application and have just added a a new link to allow users to download
<asp:LinkButton ID="lnkDownload" runat="server" Text="Download"
PostBackUrl="/download/releases/program.msi" onclick="lnkDownload_Click"
ToolTip="Download">
</asp:LinkButton>
But when I click the link I get
HTTP Error 405 - The HTTP verb used to access this page is not allowed.
I assume I need to change some setting in IIS (IIS 6) any one know what ?
The PostBackURL property of the asp:LinkButton is the wrong choice here. See the "Remarks" section of the documentation I linked:
The PostBackUrl property allows you to perform a cross-page post using the LinkButton control. Set the PostBackUrl property to the URL of the Web page to post to when the LinkButton control is clicked. For example, specifying Page2.aspx causes the page that contains the LinkButton control to post to Page2.aspx. If you do not specify a value for the PostBackUrl property, the page posts back to itself.
You can't/shouldn't use it to trigger a file download. The more appropriate control would be:
<asp:HyperLink runat="server" ID="lnkDownload" runat="server" Text="Download"
NavigateUrl="/download/releases/program.msi"></asp:HyperLink>
You could also use a "plain" <a href="/download/releases/program.msi></a>.
The page is POSTing to the MSI which will be disallowed in the Handlers section of IIS. Rather than using a LinkButton, try using an HTML link (<a> tag), this will perform a GET to the .msi file.
Alternatively, if you need POST, configure your IIS appropriately.