Link to home
Start Free TrialLog in
Avatar of jssong2000
jssong2000

asked on

Disable Hyperlink

Hi Expert,

I'd like to disable two Hyperlinks within fieldset "ExportContainer".
I successfully found the control ExportContainer and disabled it.
/HtmlGenericControl ExpContainer = (HtmlGenericControl)FileExport.FindControl("ExportContainer");
ExpContainer.Disabled = true;

<fieldset id="ExportContainer" runat="server">
    <legend>Export</legend>
    <a class="downloadFileLink"  href="<%= ResolveUrl("~/FileExport.ashx") %>" >Download All File Documents</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <a class="downloadFileLink" href="<%= ResolveUrl("~/ActiveFileExport.ashx") %>" >Download Active File Documents Only</a>
</fieldset>


But the problem is that the link still works when I clicked the link though ExportContainer has been greyed out.

Very appreciated!!
Avatar of Dustin Hopkins
Dustin Hopkins
Flag of United States of America image

You can't since the anchor tags aren't server controls. However add runat="server" and give each of them an id. Then do a findcontrol on your export container for each of them. Then you can set disabled to true just like your fieldset.
Sorry I would provide code but I'm on my mobile.

Hope this helps,
Dustin
Avatar of sybe
sybe

Why not simply remove them? What do you mean with a disabled hyperlink?
Avatar of jssong2000

ASKER

Hi Dusion, I tried but when I add runat="server" it gave me error. It looks like the link does not like runat="server" property.

Hi Sybe, I could not remove them because of requirement. Disabled Hyperlink means it won't do anything when you click the link. It's read only.

Thanks!
not sure if this'll work, but maybe some simple javascript would do the trick:

<a class="downloadFileLink"  href="<%= ResolveUrl("~/FileExport.ashx") %>" onclick="return false;" >Download All File Documents</a>

or

<a class="downloadFileLink"  href="<%= ResolveUrl("~/FileExport.ashx") %>" onclick="this.blur();">Download All File Documents</a>
> Hi Sybe, I could not remove them because of requirement. Disabled Hyperlink means it won't do anything when you click the link. It's read only.

Not sure what kind of requirement would force you to make a hyperlink that does nothing? You know, a hyperlink that does nothing is no hyperlink, it is regular text. And if you want regular text, then you remove the <a href> stuff around the text.

Also, what is the point of having a text like "download (...) documents" that does nothing?

Sorry, I am giving up trying to give an answer to your question. There is nothing like a "disabled hyperlink" and trying to disable it with javascript will only be an invitation to download anyway.

As long as you have some information about the url in the HTML, anyone will be able to copy/paste that url in the browser and download the files.
you could always just use text and then style it like a hyperlink, especially if it's never going to do anything. i just assumed it was enabled at one point and then you disabled it for some specific reason...
I am sorry. I confused everybody.

Every user could access the link and export a document before. Right now the requirement is only a user with an Analyst role could access.

.....

if (HttpContext.Current.User.IsInRole(EnumsCommon.myApp.enumRoles.Analyst.ToString()))
{
        //enable the link if you have analyst role
}
else
{
        //disable the link if you don't have analyst role
}
........
Then do not usae the "Disabled" property of your control, but the "Visible" property.

HtmlGenericControl ExpContainer = (HtmlGenericControl)FileExport.FindControl("ExportContainer");
ExpContainer.Visible = true;  //of false, whatever you need

Open in new window

If it's not an Analyst, link should be visible but disabled. It should be read only.
This is the problem I have. Thanks.
There is no such a thing as a "disabled hyperlink". and a "read-only hyperlink" is also non-existing.

Will you please explain what HTML you expect if you speak about a "disabled hyperlink".
ASKER CERTIFIED SOLUTION
Avatar of Dustin Hopkins
Dustin Hopkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If I wanted to make a page look broken, unusable, inaccessible and written by a 3-year old I guess " disabled read only links would be the way to go" however for a professional page anything that is not a link should not look like a link, should not mimic a link and most certainly should not invite a click that does nothing because it is "disabled".

I have seen a lot of backward requirements over the years, but I cannot recall anything that specifically required that the page be defective by definition.

Cd&
I made a solution.
I create another container including two labels which are similar to Hyperlinks.
I set visible and invisible to make a "disabled" It looks good.

Thanks!!
Thank you Guys.