Hiding/Showing Div In Page Depending On Search Type

2011-04-16

Think about a scenario like this You have a master section like Country & an assosciated detailed section of the master such as States of the country you selected.
If you selected a country & then a button on it's click it should display the State & related details. And also From the States details you can view the Master.

Only 1 at a time after selection.

You can do it by displaying/hiding the Div tag of Master& Details section at the window load event of the HTML. So Make a javascript function & call this by registering to the Page by using
 

Page.RegisterClientScriptBlock("OnLoadEvent", codeJavaScript);




Code Behind
---------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;



namespace MinimizeMaximizeTab

{

public partial class HTMLTips : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{



}



protected void btnShowDetails_Click(object sender, EventArgs e)

{



string codeJavaScript = "<script language=javascript>";

codeJavaScript += "window.onload = DisplayMaster;";

codeJavaScript += "function DisplayMaster()";

codeJavaScript += "{";

codeJavaScript += "document.getElementById('MasterDiv').style.visibility = 'hidden';";

codeJavaScript += "document.getElementById('DetailsDiv').style.visibility = 'visible';";

codeJavaScript += "}";

codeJavaScript += "</script>";



Page.RegisterClientScriptBlock("OnLoadEvent", codeJavaScript);

}



protected void btnShowMaster_Click(object sender, EventArgs e)

{

string codeJavaScript = "<script language=javascript>";

codeJavaScript += "window.onload = DisplayMaster;";

codeJavaScript += "function DisplayMaster()";

codeJavaScript += "{";

codeJavaScript += "document.getElementById('MasterDiv').style.visibility = 'visible';";

codeJavaScript += "document.getElementById('DetailsDiv').style.visibility = 'hidden';";

codeJavaScript += "}";

codeJavaScript += "</script>";



Page.RegisterClientScriptBlock("OnLoadEvent", codeJavaScript);

}

}

}

Works in following


0 comments: