简体   繁体   中英

Executing client-side script on link click

I need my web page to open a window and enable a disabled button when a link or a button is clicked. From what I've read on other posts on here, if I try and open a new window in Page_load most browsers will assume it's a pop-up and block it so I've been trying to do it client side with JS.

Currently, I'm trying it with a link declared like so:

Please click <a href="javascript:OpenDoc()">here</a> to open the document.

This calls the following JS:

    function OpenDoc() 
    {
        <%= btnSubmit.ClientID %>.Visible = true; 
        Window.Open('GetDocument.aspx') 
    }

Unfortunately, instead of rending the JS as "btnSubmit.Visible = true" it comes out as "MainContent_btnSubmit.Visible = true" which doesn't work.

Assuming this is the best way of doing what I want, where am I going wrong?

You can't change visibility property through javascript but you can use the following code instead of it :

var control = document.getElementById('<%=btnSubmit.ClientID %>');           
control.disabled = true;  

In this case the button will be disabled and if you need to hide button not disableing it then use the following code :

var control = document.getElementById('<%=btnSubmit.ClientID %>');           
control.style.display= "none"; 

Hope this is helpfull based on my understanding to your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM