How to make user control header load only one time?
I'm implementing a user control in an asp.net website. The user control will be used as a header in all pages. How can load the user control content 开发者_如何学运维depends on the user (logged in, logged out, user name).
How can i load my user control only one time? For example, when the user is logged in like quora. To have an idea of what i mean, log into quora, you will notice: every time,i open a page of a question,the quora header is not reloaded.only the main content changes.
How that is achieved?
I did not signup with quora, but the public pages still have a consistent header, but the header is downloaded each time a request is made. I think the simplicity makes it hard to tell that the entire screen is being redrawn.
You could use ajax to make a request and only redraw a portion of the page if that is what you desire. Or, you could go old school and use frames (please don't).
I would suggest that you put your header on a master page and have a couple of content pages. You can still put it into a user control.
If you want to keep your user control and just reload the content, it get's a bit complicated. You will have to use JavaScript to achieve this goal. In ASP.NET you could use an UpdatePanel.
<asp:UpdatePanel ID=”UpdatePanel1” runat=”server”>
<ContentTemplate>
<!-- this content can be refreshed on post backs -->
</ContentTemplate>
</asp:UpdatePanel>
To have separate panels for logged in Users, you can use login view:
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
</LoggedInTemplate>
</asp:LoginView>
精彩评论