473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Show Hide JavaScript Problem in Asp.net

Hi friend,

I've been using server control button, and on its click event i m showing or hiding the div content on the basis of its current style.

ASP code for button is:
Expand|Select|Wrap|Line Numbers
  1.  <asp:Button ID="btnClickMe" Text="Click Me...!" OnclientClick="HideDiv('PostNewTopic')" runat="Server" />
JavaScript Code is:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript" >
  2.        function HideDiv(id)
  3.        {
  4.  
  5.             if (document.getElementById(id).style.display=="none"){
  6.                 document.getElementById(id).style.display='inline';
  7.                 }
  8.             else{
  9.                 document.getElementById(id).style.display='none';
  10.                 }
  11.                    }
  12.         </script>


What the problem i m facing is on clicking the button it is hiding and again showing the div content, because the page is getting refreshed

Event is getting fired two times, so the result is same i.e, div content is shown and cannot be hidden.

help would really be appreciated.

Thank you all.
Jan 7 '08 #1
3 7283
Hi Dear,

Because you are raising the server event, your client side display will be initialize once again....

I have also faced the same problem in past...
The solution is as under..

Just add the runat="server" in your div tag of which you want to hide..
than in your button's click event, you can write
we are assuming that your div's id is divID.

divID.visible=true or divID.visible=false
as you want..

Hope this will help you..

Paresh



Hi friend,

I've been using server control button, and on its click event i m showing or hiding the div content on the basis of its current style.

ASP code for button is:

<asp:Button ID="btnClickMe" Text="Click Me...!" OnclientClick="HideDiv('PostNewTopic')" runat="Server" />


JavaScript Code is:

<script type="text/javascript" language="javascript" >
function HideDiv(id)
{


if (document.getElementById(id).style.display=="none" ){
document.getElementById(id).style.display='inline' ;
}
else{
document.getElementById(id).style.display='none';
}
}
</script>




What the problem i m facing is on clicking the button it is hiding and again showing the div content, because the page is getting refreshed

Event is getting fired two times, so the result is same i.e, div content is shown and cannot be hidden.

help would really be appreciated.

Thank you all.
Jan 7 '08 #2
Frinavale
9,735 Expert Mod 8TB
Hi friend,

I've been using server control button, and on its click event i m showing or hiding the div content on the basis of its current style.

ASP code for button is:
Expand|Select|Wrap|Line Numbers
  1.  <asp:Button ID="btnClickMe" Text="Click Me...!" OnclientClick="HideDiv('PostNewTopic')" runat="Server" />
JavaScript Code is:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript" >
  2.        function HideDiv(id)
  3.        {
  4.  
  5.             if (document.getElementById(id).style.display=="none"){
  6.                 document.getElementById(id).style.display='inline';
  7.                 }
  8.             else{
  9.                 document.getElementById(id).style.display='none';
  10.                 }
  11.                    }
  12.         </script>


What the problem i m facing is on clicking the button it is hiding and again showing the div content, because the page is getting refreshed

Event is getting fired two times, so the result is same i.e, div content is shown and cannot be hidden.

help would really be appreciated.

Thank you all.
Try using
Expand|Select|Wrap|Line Numbers
  1. <asp:Button ID="btnClickMe" Text="Click Me...!" OnclientClick="HideDiv('PostNewTopic');return false;" runat="Server" />
If this does not prevent the postback (it should though..I use this on a regular bases), consider using a simple HTML button instead.
Jan 7 '08 #3
Thank you paresh for your kindest help, thank you very much.

Hi Dear,

Because you are raising the server event, your client side display will be initialize once again....

I have also faced the same problem in past...
The solution is as under..

Just add the runat="server" in your div tag of which you want to hide..
than in your button's click event, you can write
we are assuming that your div's id is divID.

divID.visible=true or divID.visible=false
as you want..

Hope this will help you..

Paresh
Jan 8 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: oLE | last post by:
I would like to add some javascript to show/hide a certain row of a table. The first row of the table contain the hyperlink that calls the javascript the second row is the one i want to show/hide...
5
by: Mel | last post by:
i need to have 2 side by side iframes, a link on top of the one will show/hide the other can someone help me pleeeeezzzzz ?
2
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow {...
4
by: jerryyang_la1 | last post by:
I've found this script that allows be to hide/show form elements.. <script language="JavaScript"><!-- var toggle = true; function show(object) { if (document.layers && document.layers)...
4
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
7
by: FP | last post by:
I'm new to Java Script. I'm displaying comments people have made. Below each persons' comment I want to add 2 buttons "Reply" and "Amend". Clicking "Reply" would display an empty text field...
5
by: ali | last post by:
Hello every one i need you help regarding div hide and show. i am having a link like <a href="#" onClick="expandWin()">show/hide </a> <div id=showHide> </div> within div i have lots of...
18
by: Liquidtouch | last post by:
I have been searching on this for awhile and cant find anything and playing around with it got me no where. I will start with what I am after and then explain what I have. I have a table with 3...
2
by: dusk | last post by:
Hi, I have a page with lots of hidden divs which are revealed based on choices made at each 'layer'. So I've used naming convention which represents the order in which each div becomes...
1
oranoos3000
by: oranoos3000 | last post by:
hi would you please help me i have a online shopping center that i show pictures of the my product in home page. in the InterExplorer pictures is shown correctly but in Firefox browser is shown...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.