We help IT Professionals succeed at work.

AJAX.NET, MasterPage and User Control help

bemara57 asked
Medium Priority
Last Modified: 2013-11-26
In my MasterPage, I have several placeholders that have user controls in them to populate content with. I want to start using AJAX.NET with it (ASP.NET 3.5 and VS2008). This is what my MasterPage looks like:

<%@ Master Language="C#" %>
<%@ Register Src="~/Controls/Header.ascx" TagName="Header" TagPrefix="uc1" %>
<%@ Register Src="~/Controls/Menu.ascx" TagName="Menu" TagPrefix="uc1" %>
<%@ Register Src="~/Controls/MainContent.ascx" TagName="MainContent" TagPrefix="uc1" %>
<%@ Register Src="~/Controls/SubContent.ascx" TagName="SubContent" TagPrefix="uc1" %>
<%@ Register Src="~/Controls/Footer.ascx" TagName="Footer" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head ID="masterHead" runat="server">
    <link rel="stylesheet" type="text/css" href="/Global.css" />    
      <script type="text/javascript" src="/Global.js"></script>  
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:ContentPlaceHolder ID="AdminPlaceHolder1" runat="server" />
        <div id="header">
            <asp:ContentPlaceHolder ID="HeaderPlaceHolder1" runat="server">
                <uc1:Header ID="HeaderContent1" runat="server" />
        <div id="menu">
            <uc1:Menu ID="MenuPlaceHolder1" runat="server" />

        <div id="content">                    
            <asp:ContentPlaceHolder ID="MainContentPlaceHolder1" runat="server">
                <uc1:MainContent ID="MainContent1" runat="server" />

        <div id="sub-section">                    
            <asp:ContentPlaceHolder ID="SubContentPlaceHolder1" runat="server">
                <uc1:SubContent ID="SubContentContent1" runat="server" />

        <div id="footer">                
            <asp:ContentPlaceHolder ID="FooterPlaceHolder1" runat="server">            
                <uc1:Footer ID="FooterContent1" runat="server" />


I tried to put UpdatePanels around the User Controls, but got a compile error. How do I place my update panels correctly in this scenario?
Watch Question

Daniel ReynoldsSoftware Applications Developer / Integrator

I may mis-understand your efforts, but you create a masterpage to use as a template which appears to be what you are trying to do.

You then create a webform and choose the masterpage to be its template.

You appear to be putting all of your user controls in the master page, when you should want to at least put your main content in your webform that is based on the master page.

When you create the webform based on the master page, the new webform will contain the various contentplaceholders that the master page has and in those you would put your code or controls.


I'm trying to make each User Control ajax enabled by making it an update panel. This is what I tried but got a compile error:

            <asp:ContentPlaceHolder ID="HeaderPlaceHolder1" runat="server">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <uc1:Header ID="HeaderContent1" runat="server" />

I'm attempting to make the header section ajax enabled. Without Ajax as it is, everything works fine. The header has some things in that change during postbacks, so I thought putting update panels around it would make it partial reload that section. The compile error I get when I do this is that "Header" doesn't exist in the current context.
Software Applications Developer / Integrator
And it doesn't exist in the current context.

Create the Webform using the masterpage as a template and try putting your stuff into the contentplaceholder in the webform. I believe you will have better success.


My site already utilizes the User Control "header" and gets populated thru various processes. I need the User Control on the MasterPage like that. The question is how or where do I put the Update Panel? I tried putting it in the masterpage and then tried putting it within the User Control ascx page itself with no success. Can User Controls cause Ajax events on other User Controls? Say from the header to the footer user controls? Not sure how to set this up or if it's even possible.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.