Show Hide Using Panel.

We are going to implement a show hide feature by using a panel.

Add one panel,linkbutton and hiddenfield in the page,Add attributes to onclick of linkbutton and pass Panel client id,linkbutton & hiddenfield client id.And call the method ShowHide.


function ShowHide(pnlGridId,lbtnId)
{
var pnl = document.getElementById(pnlGrid);
var lbtn = document.getElementById(lbtnId);
var hdnDisplay = document.getElementById(hdnDisplayId);

if (pnl.style.display == "none")
{
pnl.style.display = "block";
lbtnShow.innerHTML = "Hide Details";
hdnDisplay.value = 'B';
}
else
{
pnl.style.display = "none";
lbtnShow.innerHTML = "Show Details";
hdnDisplay.value = 'N';
}
return false;
}



This code will work fine but if we post back the page all changes to the panel and link button will loose.So add the below code in the body onload,


function CheckShowAndHideOnLoad()
{
var pnl = document.getElementById(pnlGrid);
var lbtn = document.getElementById(lbtnId);
var hdnDisplay = document.getElementById(hdnDisplayId);

if (hdnDisplay.value == 'B')
lbtnShow.innerHTML = "Hide Details";
else if (hdnDisplay.value == 'N')
lbtnShow.innerHTML = "Show Details";
}



Now we have a Show/Hide functionality simply by using a panel.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: