Opening Explorer with HyperLink in GridView Using file:// - asp.net

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

Related

ASP.NET HyperLink

I have written an server side hyperlink which will redirect to 'landing.aspx' page. Below is the code
<asp:HyperLink ID="HyperLinkLT1" runat="server" Text="Link Text" NavigateUrl="landing.aspx"></asp:HyperLink>
This is working fine in chrome. Now the problem is when I run the project in Firefox and click on the link, I am getting a popup which says error and them the page is redirected. Below is the screen shot.
Can someone help me to identify and clear the problem.

hyperlink eval navigateurl complete path not required

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>

ASP FileUpload control issue in Chrome browser

I have a legacy webpage with an asp:FileUpload control on it with an OnClick event. When uploading an .xsls spreadsheet with parentheses () in the file name, e.g., "somefile (2).xsls," using Chrome browser, the UploadButton_Click handler is not called. Instead, the web page redirects to the default page as if an error occurred.
However, a filename without parentheses works fine. (No issue with IE.)
I need help debugging this. Breakpoints in the click handler are not hitting in this scenario. Response.Write, etc., are not good either because the event does not get hit.
The code is pretty much this:
<asp:FileUpload id="FileUpload1" runat="server">
</asp:FileUpload>
<asp:Button id="UploadButton"
Text="Upload file"
OnClick="UploadButton_Click"
runat="server">
</asp:Button>

404 error on link button click to valid website address

When a user clicks on this particular link button in question, I receive a 404 error in the browser. When I click the refresh button on the browser, the target website loads as normal. Any thoughts on what this might be? It's just a plain old .net link button:
<asp:LinkButton ID="lnkWhatAre" runat="server" ForeColor="#FF9999"
Style="text-decoration: none" CausesValidation="false"
PostBackUrl="http://www.targetsite.com/">WHAT ARE?</asp:LinkButton>
PostBackUrl causes page to perform POST request, not all target pages like it. If you simple mean to provide a navigation link you can use something like this instead:
<asp:HyperLink ID="lnkWhatAre" runat="server" ForeColor="#FF9999"
Style="text-decoration: none"
NavigateUrl="http://www.targetsite.com/">WHAT ARE?</asp:HyperLink>
"asp:HyperLink" is a server-side control, so you can still set all its properties in server-side code if needed. And it renders as a normal hyperlink - so it won't cause any problems redirecting.

link button property to open in new tab?

In my application I have some link buttons there but when I right click on them I cannot (they are in disable mode) find the menu items Open in new tab or Open in new window.
How do I show those menu items?
Code example:
<asp:LinkButton id="lbnkVidTtile1" runat="Server" CssClass="bodytext" Text='<%#Eval("newvideotitle") %>' />
From the docs:
Use the LinkButton control to create a hyperlink-style button on the Web page. The LinkButton control has the same appearance as a HyperLink control, but has the same functionality as a Button control. If you want to link to another Web page when the control is clicked, consider using the HyperLink control.
As this isn't actually performing a link in the standard sense, there's no Target property on the control (the HyperLink control does have a Target) - it's attempting to perform a PostBack to the server from a text link.
Depending on what you are trying to do you could either:
Use a HyperLink control, and set the Target property
Provide a method to the OnClientClick property that opens a new window to the correct place.
In your code that handles the PostBack add some JavaScript to fire on PageLoad that will open a new window correct place.
Here is your Tag.
<asp:LinkButton ID="LinkButton1" runat="server">Open Test Page</asp:LinkButton>
Here is your code on the code behind.
LinkButton1.Attributes.Add("href","../Test.aspx")
LinkButton1.Attributes.Add("target","_blank")
Hope this will be helpful for someone.
Edit
To do the same with a link button inside a template field, use the following code.
Use GridView_RowDataBound event to find Link button.
Dim LB as LinkButton = e.Row.FindControl("LinkButton1")
LB.Attributes.Add("href","../Test.aspx")
LB.Attributes.Add("target","_blank")
try by Adding following onClientClick event.
OnClientClick="aspnetForm.target ='_blank';"
so on click it will call Javascript function an will open respective link in News tab.
<asp:LinkButton id="lbnkVidTtile1" OnClientClick="aspnetForm.target ='_blank';" runat="Server" CssClass="bodytext" Text='<%# Eval("newvideotitle") %>' />
This is not perfect, but it works.
<asp:LinkButton id="lbnkVidTtile1" runat="Server"
CssClass="bodytext" Text='<%# Eval("newvideotitle") %>'
OnClientClick="return PostToNewWindow();" />
<script type="text/javascript">
function PostToNewWindow()
{
originalTarget = document.forms[0].target;
document.forms[0].target='_blank';
window.setTimeout("document.forms[0].target=originalTarget;",300);
return true;
}
</script>
LinkButton executes HTTP POST operation, you cant change post target here.
Not all the browsers support posting form to a new target window.
In order to have it post, you have to change target of your "FORM".
You can use some javascript workaround to change your POST target, by changing form's target attribute, but browser will give a warning to user (IE Does), that this page is trying to post data on a new window, do you want to continue etc.
Try to find out ID of your form element in generated aspx, and you can change target like...
getElementByID('theForm').target = '_blank' or 'myNewWindow'
When the LinkButton Enabled property is false it just renders a standard hyperlink. When you right click any disabled hyperlink you don't get the option to open in anything.
try
lbnkVidTtile1.Enabled = true;
I'm sorry if I misunderstood. Could I just make sure that you understand the purpose of a LinkButton? It is to give the appearance of a HyperLink but the behaviour of a Button. This means that it will have an anchor tag, but there is JavaScript wired up that performs a PostBack to the page. If you want to link to another page then it is recommended here
that you use a standard HyperLink control.
It throws error.
Microsoft JScript runtime error: 'aspnetForm' is undefined
<asp:LinkButton ID="LinkButton1" runat="server" target="_blank">LinkButton</asp:LinkButton>
Use target="_blank" because It creates anchor markup. the following HTML is generated for above code
<a id="ctl00_ContentPlaceHolder1_LinkButton1" target="_blank" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$LinkButton1','')">LinkButton</a>

Resources