最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - style.visibility not working in FireFox - Stack Overflow

programmeradmin1浏览0评论

I am having an aspx page with a panel. I am using the panel as to show a messagebox. The panel id is "panMessage". The panel contains a button label "Hide". I am showing the panel using code behind but need to close the panel with JS when user clicks on Hide button. I have attached the following code with onclick event of the button -

onclick="javascript:(<%=panMessage.ClientID%>).style.visibility='hidden';"

the click event works perfectly in IE but not in FireFox. I have googled and changed the code as -

onclick="javascript:(<%=panMessage.ClientID%>).style.display='none';"

but still the code is not working i.e. the panel is not going to hide in FireFox although it works in IE using this new code also.

Could someone guide me whats wrong i have done?

Thanks for your cooperation.

I am having an aspx page with a panel. I am using the panel as to show a messagebox. The panel id is "panMessage". The panel contains a button label "Hide". I am showing the panel using code behind but need to close the panel with JS when user clicks on Hide button. I have attached the following code with onclick event of the button -

onclick="javascript:(<%=panMessage.ClientID%>).style.visibility='hidden';"

the click event works perfectly in IE but not in FireFox. I have googled and changed the code as -

onclick="javascript:(<%=panMessage.ClientID%>).style.display='none';"

but still the code is not working i.e. the panel is not going to hide in FireFox although it works in IE using this new code also.

Could someone guide me whats wrong i have done?

Thanks for your cooperation.

Share Improve this question edited Nov 27, 2009 at 13:42 DOK 32.9k8 gold badges63 silver badges93 bronze badges asked Nov 27, 2009 at 13:33 IrfanRazaIrfanRaza 3,05817 gold badges65 silver badges90 bronze badges 1
  • Show us the rendered HTML --> run your page, view source, copy/paste relevant HTML. – cllpse Commented Nov 27, 2009 at 13:34
Add a ment  | 

4 Answers 4

Reset to default 4

It seems to me that the problem lies with (<%=panMessage.ClientID%>).

onclick="(<%=panMessage.ClientID%>).style.display='none';"

When rendered would give something like:

onclick="(panMessage_1).style.display='none';"

You should put something like:

onclick="document.getElementById('<%=panMessage.ClientID%>').style.display='none';"

First of all, visibility hidden and display none are not the same. The former will make the element consume the same space as it would have, if it would've been visible, whereas the latter won't. display: none is synonymous to visibility: hidden; position: absolute;

Other than that, your problem is probably due to the way you access your element. Try changing to the following:

onclick="document.getElementById('<%=panMessage.ClientID%>').style.display='none';"

Use

document.getELementById ( "<%=panMessage.ClientID%>" ) to retrieve the element and then try setting the display or visibility attribute.

Set the display attribute to none so that the control won't take the space.

We'd really need to see the actual HTML output to be able to debug it for you.

The correct output should look something like this:

onclick="document.getElementById('panMessage').style.display='none';"

Note that you don't need javascript: in the event handlers.

发布评论

评论列表(0)

  1. 暂无评论