Wednesday, 6 March 2013

Refresh only content place holder without refreshing master page


Refresh only content place holder without refreshing master page
  • Create menu.ascx and edit as 
<div class="menu">
    <ul>
        <li><a href="Default.aspx?menu=Home">Home</a></li>
        <li><a href="Default.aspx?menu=Admin">Admin</a></li>
        <li><a href="Default.aspx?menu=About">About</a></li>
    </ul>   
</div>

  • Create 
    1. Home.ascx
    2. Admin.ascx
    3. About.ascx
  • change masterpage.master.cs file
 protected void Page_Load(object sender, EventArgs e)
    {
        LoadMenu();
    }

    private void LoadMenu()
    {
        string menu = Request.QueryString["menu"];
        Control c;
        switch (menu)
        {
            case "Home":
                c = Page.LoadControl(Request.ApplicationPath + "/UserControlMenu/LeftMenuHome.ascx");
                break;
            case "Admin":
                c = Page.LoadControl(Request.ApplicationPath + "/UserControlMenu/LeftMenuAdmin.ascx");
                break;
            case "About":
                c = Page.LoadControl(Request.ApplicationPath + "/UserControlMenu/LeftMenuAbout.ascx");
                break;
            default:
                c = Page.LoadControl(Request.ApplicationPath + "/UserControlMenu/LeftMenuHome.ascx");
                break;
        }
        leftMenuContentPlaceHolder.Controls.Add(c);
    }

No comments:

Post a Comment