Solved

Disable Hyperlink

Posted on 2013-11-11
14
369 Views
Last Modified: 2013-11-13
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
Comment
Question by:jssong2000
  • 5
  • 4
  • 2
  • +2
14 Comments
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 39640312
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
 
LVL 28

Expert Comment

by:sybe
ID: 39640836
Why not simply remove them? What do you mean with a disabled hyperlink?
0
 

Author Comment

by:jssong2000
ID: 39641608
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
 
LVL 32

Expert Comment

by:Big Monty
ID: 39641657
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
 
LVL 28

Expert Comment

by:sybe
ID: 39641760
> 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
 
LVL 32

Expert Comment

by:Big Monty
ID: 39641774
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
 

Author Comment

by:jssong2000
ID: 39641999
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 28

Expert Comment

by:sybe
ID: 39642066
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
 

Author Comment

by:jssong2000
ID: 39642141
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
 
LVL 28

Expert Comment

by:sybe
ID: 39642161
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
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 500 total points
ID: 39642258
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39642319
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
 

Author Comment

by:jssong2000
ID: 39644759
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
 

Author Closing Comment

by:jssong2000
ID: 39644773
Thank you Guys.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now