hyperlink eval navigateurl complete path not required - asp.net

In database I have a column for website name. This website I am displaying inside a listview in a hyperlink field. I want that when user click on the link it should redirect to the website in new tab but right now when clicking the folder structure is prefixing before the website name. Here is the code for Hyperlink. What should I do to remove the prefix from website name. The text of website is displaying fine. Please advice:
<asp:HyperLink ID="hplWebsite" runat="server" style="text-decoration: underline;" Text='<%# Eval("Website")%>' NavigateUrl='<%# Eval("Website")%>' Target="_blank"></asp:HyperLink>

Related

Adding a click event to a Hyperlink displayed in ListView VB.NET ASP.NET

Is there a way to add a click event to a Hyperlink tag that's render in ListView?
Basically, I have a HyperLink tag that generates a link dynamically and it opens up to a new tab when users click on it. At the same time, when the user click on it, I want to post a text or make the text label visible. Sample code below:
<asp:ListView ...>
<ItemTemplate>
<asp:Label ID="Msg" Text="*You have already accessed this link*" runat="server" Visible="false"/>
<asp:HyperLink ID="label1" NavigatUrl='<%#Eval("Link")%>'Target="_blink" text="Click Link" runat="server"></asp:HyperLink>
<//ItemTemplate>
</asp:ListView>
You can use QueryString. Add the link with a Query Parameter on it and then -
If IsPostBack=True then 'Check if the page is reloading [Because when you clik on the link with the same link, it will reload the page]
'Considering the QueryString will be like - "yourdomain/default.aspx?item=1"
'Check for QueryString
Dim s_ItemId As String = Request.QueryString("item")
if s_ItemId<>"" then
'Do whatever you want
End If

Using LinkButton PostbackUrl - new window/tab needed to open

Im posting and redirecting to a third party by setting the PostBackUrl property on a LinkButton.
My problem is that I want this to open in a new tab but target="_blank" doesnt do anything here.
<asp:LinkButton ID="hlApplication" runat="server" Text="Start your application" aria-describedby="information" target="_blank" OnClientClick="this.disabled=true;" UseSubmitBehavior="false"/>
hlApplication.PostbackUrl ="http://externalurl";
Any ideas how I can do this?
Try this:-
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='http://www.google.com' Target="_blank">Google </asp:HyperLink>
In this instance, we had to have a hyperlink that opened a new tab that contained the form. This form is automaticaly posted by Javascript and the user taken to their destination. This was the only way we could get this to work

Open image on next aspx page

I show image thumbnails on page, Now I want when i click on image thumbnail the big images related to that thumbnail open in IamgeDispData.aspx page where i created a data entry form in that page to enter data related to that picture. How can I do this? With help of query string or else??
Query String is a good option.
What you can do put your image inside a asp:hyperlink
Set the URL of asp:hyper link with querysting
And in your detail page get it from url
Note that you can only pass the filepath in the url
And you will have to show it from the physical location
With help of query string ??
Yes, you can use it. Just surround your image with <a> anchor tag or use asp:hyperlink server side tag.
It can be something like
Content/Thumbnails/page.aspx?imageName="your image name"
e.g.
<a href="http://www.espn.com" target="_blank">
<img src="ahman.gif" />
</a>
Ref:
html - image links
Hyperlink image
How to control the image size of a Hyperlink?
example code snippet:
<asp:HyperLink runat="server" ID="hlThumbnail" NavigateUrl='<%# Eval("Url") %>'
Target="_blank" Style="height: 66px;">
<asp:Image runat="server" ID="imgThumbnail" Height="66px"
ImageUrl='<%# Eval("Thumbnail") %>' />
</asp:HyperLink>
In case you have no issue in showing Id to user , it will be the best solution. In case you have some issue in showing Id , you can encrypt it and then use it as Id. You can also validate then user again in the ImageDispData.aspx if he has the permission to enter the data or not for the image.
I am giving way to use using querystring and javascript.
You can use window.open function of JavaScript to open in new window or tab. When you are generating the thumbnail image , create them with url like : yourBigimage.aspx?photoId=10 , open this url using jquery onclick event of image and use window.open

URL rewriting in ASP.NET 4.0 on radiobutton check event

I am trying to change URL of website and need help for the same. The scenario is that I have a search engine for student search and have different criteria for refine search. By default I am showing all the student data on homepage and when we use search the result is displayed on the same page, so URL of the page does not change.
My search criteria are by date of join(1 month,2months,6months,1Yr) and state they belong from. I have added radio button for refine search, so on "OnCheckedChanged" event the data gets populated on the page. So now how do I change the URL so as to show something like, say I have website www.xyz.com and need to show www.xyz.com/bydate/1month or www.xyz.com/bystate/LA. Have googled many links but not able to understand how to start.
Below is snippet of my code
<asp:DataList ID="dlJoin" CssClass="slider" r RepeatColumns="1" RepeatDirection="Vertical" runat="server" OnItemDataBound="dlJoin_ItemDataBound">
<ItemTemplate>
<label style="text-align: left; margin-left:15px;">
<asp:RadioButton ID="rddlJoin" CssClass="radiobooking" Checked="false" AutoPostBack="true" OnCheckedChanged="rddlJoin_checkchanged" GroupName="rdGroupTag" runat="server" onKeyPress="return suppress(event);" /><%#Eval("Name")%>
</label>
<asp:Literal runat="server" Visible="false" ID="litdlJoin" Text='<%#Eval("Value")%>'></asp:Literal>
</ItemTemplate>
</asp:DataList>
I would do this with Javascript and not worry about redirecting on the server side(assuming that all your clients should have javascript). You can do a "pure" redirect by using something like
window.location.href = "http://xyz.com/bydate/1month";
This has equivalent behavior as to if you clicked on a link to that URL.
If you're wanting to use Ajax and make things be a bit nicer looking(and no full page loads) you can use a combination of # URL changes and using a tool like jQuery to easily load a div or some such from another URL

Opening Explorer with HyperLink in GridView Using file://

I am trying to open Explorer on the client side to view a directory. In my aspx webform, I have a gridview, which has a column of hyperlinks. In the aspx markup, I have the following:
<asp:HyperLink Text="ICPnt" id="MyDir" runat="server" Target="_blank" NavigateUrl='<%# "file://" + Eval("MyDir").ToString() %>' ></asp:HyperLink>
When the startup the asp.net application in debug mode with Visual Studio and move the cursor over the hyperlink, I see the popup path,
file://MachineName/C$/WINNT/MyDir
This looks correct. When I click on the hyperlink, NOTHING happens. I don't even see the cursor turning to an hourglass icon or anything. I think I am pretty close but can't see the missing step or error.
Another test:
I typed file://MachineName/C$/WINNT/MyDir in both Windows and Internet Explorer and got a new Explorer to pop up and display the directory content from my VM environment. As a test, I copied and pasted the same exact file:// path to my aspx markup and tested again. When I click on it, nothing happens.
<asp:HyperLink Text="ICPnt" id="WSM2MDir" runat="server" Target="_blank" NavigateUrl='<%# "file://MachineName/C$/WINNT/MyDir" %>' ></asp:HyperLink>
Any help is appreciated. THanks

Resources