Skip to content

Replies

0
Sri Denduluri
Sri Denduluri answered on Dec 21, 2016 1:19 PM

hi mike, I create a demo for u, when u run it I hard coded a break point when u hover over the control u wil see that it is null. I need tyur email address so I can send directly to you?

0
Sri Denduluri
Sri Denduluri answered on Dec 19, 2016 5:06 PM

hi Michael, I have another problem I got the template to load, by storing the data table in memory (session), and it loads fine after postback, now have another problem. The template contains control, a usercontrol is one of the many controls it contains (see below 'UserControl'), now the problem is this, when rowInitialize, and or when Page_Load occurs, and it calls the Usercontrols Page_Load event, the controls (see below 'lblHeader', 'grdLabResults') are null, why is this shouldn't this be automatic, when the controls have been created as I have done below in the Usercontrol page file, also see my code-behind file as well.

UserControl (LabResults)

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucLabResults.ascx.cs" Inherits="AwareDocEduWeb.UserControls.ucLabResults" %>
<div></div>
<div id="header" align="center">
    <asp:Label ID="lblHeader" runat="server" Text="" Font-Size="XX-Large"></asp:Label>
</div>
<div>
</div>
<div style="margin: 20px 20px 20px 20px">
    <asp:GridView ID="grdLabResults" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" Font-Names="Arial" Font-Size="8pt" Width="800px" OnRowCommand="grdLabResults_RowCommand" OnLoad="grdLabResults_Load">
        <AlternatingRowStyle BackColor="#F7F7F7" />
        <Columns>
            <asp:BoundField DataField="Item Name" HeaderText="Item Name" />
            <asp:BoundField DataField="Order Name" HeaderText="Order Name" />
            <asp:TemplateField HeaderText="Previous">
                <ItemTemplate>
                    <asp:ImageButton ID="imgPrev" runat="server" CommandName="Previous" CommandArgument='<%# string.Format("{0}%{1}%{2}", Eval("OrderID"), Eval("Arrival Date"), Eval("Item Name")) %>' />
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Description">
                <ItemTemplate>
                    <asp:ImageButton ID="imgDesc" runat="server" CommandName="Description" CommandArgument='<%# Eval("Value") %>' />
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:BoundField DataField="Value" HeaderText="Value" />
            <asp:BoundField DataField="H/L" HeaderText="H/L" />
            <asp:BoundField DataField="Range" HeaderText="Range" />
            <asp:BoundField DataField="Arrival Date" HeaderText="Arrival Date" />
            <asp:BoundField DataField="OrderID" HeaderText="OrderID" Visible="False" />
            <asp:BoundField DataField="Arrival" HeaderText="Arrival" Visible="False" />
        </Columns>
        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" Height="30px" />
        <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
        <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" Height="20px" />
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
        <SortedAscendingCellStyle BackColor="#F4F4FD" />
        <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
        <SortedDescendingCellStyle BackColor="#D8D8F0" />
        <SortedDescendingHeaderStyle BackColor="#3E3277" />
    </asp:GridView>
</div>
Usercontrol (LabResults) Code-Behind

public partial class ucLabResults : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.FillLabResultsGrid(); // put a break point here u will see that 'lblHeader' and 'grdLabResults' is null
                this.lblHeader.Text = "Lab Results for " + "Some Patient name";
            }
            catch (Exception ex)
            {
                Common.CommonFacade.CommonFacadeAccess.LogError(ex, this._UserID);
            }
        }
}
ModalPopup Template
public abstract class ModalPopupItemTemplate : System.Web.UI.ITemplate
    {
        #region "Variables"
        private Page _MyParentForm;
        private ImageButton _btnTargetControl = new ImageButton();
        private ModalPopupExtender _ModalMainPopupExtender = new ModalPopupExtender();
        private Panel _PanelPopupControl = new Panel();
        private HtmlGenericControl _div1 = new HtmlGenericControl("div");
        private HtmlGenericControl _div2 = new HtmlGenericControl("div");
        private UserControl _ucMainUserControl = null;
        private Button _btnOkControl = new Button();
        private readonly List<Control> _ListAdditionalContainerControls = new List<Control>();
        #endregion
        #region "Properties"
        public Page MyParentForm
        {
            get { return _MyParentForm; }
        }
       
        public ImageButton BtnTargetControl
        {
            get { return _btnTargetControl; }
        }
        public ModalPopupExtender ModalMainPopupExtender
        {
            get { return _ModalMainPopupExtender; }
        }
        public Panel PanelPopupControl
        {
            get { return _PanelPopupControl; }
        }
        protected HtmlGenericControl Div1
        {
            get { return _div1; }
        }
        protected HtmlGenericControl Div2
        {
            get { return _div2; }
        }
        protected UserControl ucMainUserControl
        {
            get { return _ucMainUserControl; }
            set { _ucMainUserControl = value; }
        }
        protected Button BtnOkControl
        {
            get { return _btnOkControl; }
        }
        protected List<Control> ListAdditionalContainerControls
        {
            get { return _ListAdditionalContainerControls; }
        }
        #endregion
        #region "Constructor"
        protected ModalPopupItemTemplate()
        {
        }
        protected ModalPopupItemTemplate(Page myParentForm, UserControl uc)
            : this()
        {
            _ucMainUserControl = uc;
            _MyParentForm = myParentForm;
            this.Init();
        }
        #endregion
        #region ITemplate Members
        protected void Init()
        {
            BtnTargetControl.ID = "btnTargetControl";
            ModalMainPopupExtender.TargetControlID = "btnTargetControl";
            ModalMainPopupExtender.PopupControlID = "PanelPopupControl";
            ModalMainPopupExtender.OkControlID = "btnOkControl";
            ModalMainPopupExtender.DropShadow = true;
            PanelPopupControl.ID = "PanelPopupControl";
            PanelPopupControl.HorizontalAlign = HorizontalAlign.Center;
            PanelPopupControl.BackColor = Color.White;
            PanelPopupControl.Height = new Unit(450);
            PanelPopupControl.Width = new Unit(400);
            PanelPopupControl.Style.Add(HtmlTextWriterStyle.Display, "none");
            PanelPopupControl.Style.Add(HtmlTextWriterStyle.BorderStyle, "solid");
            PanelPopupControl.Style.Add(HtmlTextWriterStyle.BorderWidth, "2px");
            PanelPopupControl.Style.Add(HtmlTextWriterStyle.BorderColor, "black");
            PanelPopupControl.Style.Add("align-items", "center");
            PanelPopupControl.Controls.Add(Div1);
            PanelPopupControl.Controls.Add(Div2);
            if (ucMainUserControl == null)
            {
                ucMainUserControl = new UserControl();
                Label lblHeader = new Label();
                var divInner = new HtmlGenericControl("div");
                divInner.Style.Add(HtmlTextWriterStyle.VerticalAlign, "center");
                divInner.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
                divInner.Style.Add("align-items", "center");
                lblHeader.Text = "<h1>You need to add a custom user Control</h1>";
                divInner.Controls.Add(lblHeader);
                ucMainUserControl.Controls.Add(divInner);
            }
            ucMainUserControl.ID = "ucMainUserControl1";
            BtnOkControl.ID = "btnOkControl";
            Div1.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
            Div1.Style.Add(HtmlTextWriterStyle.Height, "400px");
            Div1.Controls.Add(ucMainUserControl);
            Div2.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
            Div2.Controls.Add(BtnOkControl);
        }
        public void InstantiateIn(Control container)
        {
            container.Controls.Add(BtnTargetControl);
            if (_ListAdditionalContainerControls.Any())
            {
                foreach (var c in _ListAdditionalContainerControls)
                    container.Controls.Add(c);
            }
            container.Controls.Add(ModalMainPopupExtender);
            container.Controls.Add(PanelPopupControl);
        }
        #endregion
    }
0
Sri Denduluri
Sri Denduluri answered on Dec 19, 2016 3:15 PM

ok, I will try that

0
Sri Denduluri
Sri Denduluri answered on Dec 16, 2016 4:27 PM

Hi Michael,

yes I know I have to re-set the cells template after postback but which event do I use to do this, and I don't have to make repeated database calls to do this do I? Cuz it uses value from a table to determine which cell is assign the template or not?