Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

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!!
0
jssong2000
Asked:
jssong2000
  • 5
  • 4
  • 2
  • +2
1 Solution
 
Dustin HopkinsSenior Web DeveloperCommented:
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
0
 
sybeCommented:
Why not simply remove them? What do you mean with a disabled hyperlink?
0
 
jssong2000Author Commented:
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!
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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>
0
 
sybeCommented:
> 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.
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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...
0
 
jssong2000Author Commented:
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
}
........
0
 
sybeCommented:
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

0
 
jssong2000Author Commented:
If it's not an Analyst, link should be visible but disabled. It should be read only.
This is the problem I have. Thanks.
0
 
sybeCommented:
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".
0
 
Dustin HopkinsSenior Web DeveloperCommented:
jssong,

Why not just make them asp hyperlink controls and leave the navigateurl prop off, essentially giving you a disabled hyperlink by default?

Then on the server side check the user role and enable it if the user is in the correct role.

Controls:
   <fieldset id="ExportContainer">
    <legend>Export</legend>
    <asp:hyperlink runat="server" ID="hlFileExport" class="downloadFileLink">Download All File Documents</asp:hyperlink>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <asp:hyperlink runat="server" ID="hlActiveFileExport" class="downloadFileLink">Download Active File Documents Only</asp:hyperlink>
</fieldset>

Open in new window

Enabler:
 if (HttpContext.Current.User.IsInRole(EnumsCommon.myApp.enumRoles.Analyst.ToString()))
            {
                //var ExpContainer = (HtmlGenericControl)FileExport.FindControl("ExportContainer");
                var hlFileExp = (HyperLink)FileExport.FindControl("hlFileExport");
                var hlActiveFileExp = (HyperLink)FileExport.FindControl("hlActiveFileExport");

                hlFileExp.NavigateUrl = ResolveUrl("~/FileExport.ashx");
                hlActiveFileExp.NavigateUrl = ResolveUrl("~/ActiveFileExport.ashx");
            }

Open in new window


This may not be the most elegant solution, but it should fit the bill.
Hope this helps,
Dustin
0
 
COBOLdinosaurCommented:
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&
0
 
jssong2000Author Commented:
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!!
0
 
jssong2000Author Commented:
Thank you Guys.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 5
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now