Solved

Disable Hyperlink

Posted on 2013-11-11
14
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
LVL 33

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 33

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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

734 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