How to make a button not visible but still use javascript?

I am using a button that should be unsafe and should be used by the javascript function.

<asp:Button ID ="btnDummy1" runat="server" Visible ="true" OnClick="btnSubmit1_Click" width="0px" height="0px"/ 

I cannot keep visible = false, since javascript will not use invisible content in poage. I havetried to give width = 0 and height = 0, yet it displays in Chrome. What do you guys think I should do?

Thank you in advance:)

+4
source share
6 answers

A fairly clean approach in ASP.Net gives it a "hidden" class:

 <asp:Button ID ="btnDummy1" runat="server" CssClass="hidden" /> 

Then in your stylesheet:

 .hidden { display: none; } 
+11
source

If you set it to Visible="False" , then the code will not be executed.

Instead, I think you should wrap it in and set display:none via css:

 <div style="display: none;"> <asp:Button ID ="btnDummy1" runat="server" OnClick="btnSubmit1_Click" /> </div> 
+3
source

What about

 style="display:none" 

for the button instead of Visible = "true".

0
source

Can you just use the hidden form field in this case? This is usually the preferred method of transmitting information.

See http://www.tizag.com/htmlT/htmlhidden.php

0
source

adding style = "display: none" will hide the button until you see it again

 <asp:Button ID ="btnDummy1" runat="server" OnClick="btnSubmit1_Click" style="display:none"/> 
0
source

I think the first question you should ask yourself is: why should I enter a button in my HTML document that should not be visible?

The HTML document should be used ONLY to describe the semantics of the CONTENT. Therefore, the HTML document should ONLY contain the content that you want to publish, and additional data to explain the content of SEMANTIC !! NOTHING about how it is displayed, NOTHING, about how it behaves!

All display and behavior questions should be managed using CSS and Javascript, NEVER in the HTML itself.

Any element needed for a Javascript-only purpose should be added to the document directly using Javascript!

You should never find things like the previous / next buttons for a javascript image gallery in an HTML document, for example. The HTML document should contain only a list of images, than your JS script will change the way this list is displayed, making it a vowel gallery and add buttons for navigation.

So, in your example, your statement that you want to add an invisible button to your HTML document with some Javascript actions on it ... this is probably an example of some content that should never be in an HTML document.

-1
source

Source: https://habr.com/ru/post/1332759/


All Articles