Solved

Disable Hyperlink

Posted on 2013-11-11
14
368 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…

747 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

12 Experts available now in Live!

Get 1:1 Help Now