c# - Design Advice using Master Pages -


master page

  <div id="header" style="height: 150px; width: 750px;">         <asp:label id="label3" runat="server" text="loggedinuser:"></asp:label>         <asp:label id="lblloggedinuser" runat="server" text=""></asp:label>     </div>     <div id="leftmenu" class="leftmenu">           <br />         <asp:dropdownlist id="ddlfamilymembers" runat="server"                style="height: 25px; width: 125px" datatextfield="fullname"                datavaluefield="membershipgen"                onselectedindexchanged="ddlfamilymembers_selectedindexchanged"                autopostback="true" >         </asp:dropdownlist>           <br /><br />           <asp:image id="imagemember" class="space" runat="server" height="150px" width="125px" />           <br /><br /><br />         <asp:label id="label1" runat="server" class="space" text="membershipid:"></asp:label>         <asp:label id="lblmembershipid" runat="server" text=""></asp:label>          <br />         <asp:label id="label2" runat="server" class="space"  text="name:"></asp:label>         <asp:label id="lblmembername" runat="server" text=""></asp:label>          <br /><br /><br />           <asp:linkbutton id="lbinformation" class="space" runat="server" onclick="lbinformation_click">member information</asp:linkbutton><br />           <asp:linkbutton id="lbaddress" class="space" runat="server"                onclick="lbaddress_click">member address</asp:linkbutton>     </div>  <div id="divright" class="divright">         <asp:contentplaceholder id="cphmain" runat="server">         </asp:contentplaceholder>         </div> 

i posted masterpage code can better understand issue. since these controls in master page needed create public properties controls in masterpage databind content pages. maybe approaching wrong how planning on achieving this.

contentpage default.aspx page_load event call method retrieve data , set dropdownlist, image, 2 label fields. on selected index change of dropdownlist grab new values method , populate controls accordingly.

to access these controls in master page read can couple of different ways 1 <%@mastertype virtualpath="~/member.master" %> , create typed connection. or create loosely type connection.

my problem these ways going have on 15 content pages , hate have rebind dropdownlist every time 1 of content pages called. have reinstantiate controls in every method of content pages assume doing wrong.

can give me advice on proper way achieve without repetitive code?

you've got right idea, trying decouple parent child, think way want may clunky.

assuming can this, i'd follows:

  • make public method bindfamilymembers(string parameter) on master page's code-behind.

  • from child page, pass necessary unique parameters bindfamilymembers master method.

this way don't need expose controls themselves, expose method modifies controls based on parameters.

edit

you want notify child page ddl selectedindex has changed. great case custom events.

you can configure event on master page child page listens for. when ddl.selectedindex changes, can fire custom event (and pass selected information) via custom event, , child page listening can handle event.

there lot of examples of custom events online. here's 1 can start with: http://www.marten-online.com/csharp/simple-custom-event-handling.html


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -