tags:

views:

58

answers:

4

I have a link

        <asp:HyperLink ID="BtnPrint" runat="server"
               NavigateUrl="~/CrystalReportViewer.aspx" Visible="false"
               Target="_blank" ToolTip="Print pdf">Print</asp:HyperLink>

I want that when I click to show it should be visible.. that's working... but I want that when I click to this hyper link it should be invisible or not enabled...

or is it possible to show page in new tab or window by using asp button or asplinkbutton?

+3  A: 

Are you sure the user will not cancel the print on accident and need to reclick the link?

<a href="#" onclick="this.disabled=true">test</a>

or in code

myPrintLink.Attributes.Add("onclick", "this.disabled=true")
asawyer
not working or me
Sheetal Inani
If your using an asp:hyper link it's probably easier to add the attribute on page load, as there is no 'onclientclick' for that control.
asawyer
is page should be postback to disable the link????????
Sheetal Inani
m sure that the user will not cancel the print on accident becouse it will be visible after clicking on some button
Sheetal Inani
The Attributes.Add call simply adds an attribute/value pair to the html element. In this case we are adding an attribute that javascript happens to know how to parse and do something special with the value, ie disable the DOM control.
asawyer
Did you actually test this code? It doesn't work in IE 6 anyway. Nor in FF, nor Chrome.
Daniel Dyson
Yes, I did. What isn't working?
asawyer
I think you forgot to test it with Target="_blank". If you include that, your example doesn't work.
Daniel Dyson
Hm ya got me, I did not try that.
asawyer
It is an easy mistake to make. Turned out not to be a very easy requirement.
Daniel Dyson
A: 

You can hide the hyperlink using simple javascript's visible property.

omniprasan
A: 

You can try

<a href="http://www.example.com" onclick="return false">
anish
This will prevent the link from working, rather than disabling it after it has worked.
Daniel Dyson
A: 

Try this in your code behind

    protected void Page_Load(object sender, EventArgs e)
    {
        BtnPrint.Attributes.Add("onclick","this.style.display='none';");
    }

This will set your link to invisible after it is clicked.

If you really want to disable the link, it is kind of complicated. This is because hyperlinks don't support the disabled attribute in all browsers. Have a look at this idea from Microsoft Support

Daniel Dyson