Link to home
Start Free TrialLog in
Avatar of bemara57
bemara57

asked on

AJAX.NET, MasterPage and User Control help

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">
    <title></title>
    <link rel="stylesheet" type="text/css" href="/Global.css" />    
      <script type="text/javascript" src="/Global.js"></script>  
</head>
<body>
    <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" />
            </asp:ContentPlaceHolder>
        </div>
   
        <div id="menu">
            <uc1:Menu ID="MenuPlaceHolder1" runat="server" />
        </div>

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

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

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

    </form>
</body>
</html>

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?
Avatar of Daniel Reynolds
Daniel Reynolds
Flag of United States of America image

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.
Avatar of bemara57
bemara57

ASKER

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" />
                </asp:UpdatePanel>
            </asp:ContentPlaceHolder>

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.
ASKER CERTIFIED SOLUTION
Avatar of Daniel Reynolds
Daniel Reynolds
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.