hello (sorry poor title)
i have user control loads different additional user controls based on conditions this:
<%@ control language="c#" autoeventwireup="true" codefile="subpage.ascx.cs" inherits="subpage" %> <%@ register src="<srca>" tagname="a" tagprefix="ctrl" %> <%@ register src=">srcb>" tagname="b" tagprefix="ctrl" %> <% if (somevalue == 1) { %> loading user control a.. <ctrl:a runat="server" /> <% } else { %> loading user control b.. <ctrl:b runat="server" /> <% } %>
the result correct; expected content displayed. noticed though somevalue != 1 , control b displayed, control still loaded behind scenes (page load called).
why this? , better approach? thanks.
page_load called because handle event. don't try load them in way use visible-property instead codebehind.
expose public function controller(in case subpage.ascx
) calls after changed visible state load content of usercontrol. controls aren't visible won't rendered html @ all.
loading controls dynamically if don't need can cause unnecessary viewstate- or event-handling issues. here other disadvantages mentioned regarding dynamic usercontrols.
Comments
Post a Comment