Kavi suja

Kavi suja

  • NA
  • 298
  • 171.5k

Header ---- .ascx file - Can't be displayed properly

Aug 2 2013 2:17 AM
Hi,
    I use .ascx file for Header alignment in my project.Here in Header.ascx I add the following code:

<asp:Table ID="tblHeader" runat="server" Width="100%" CellPadding="0" CellSpacing="0">
<asp:TableRow>

<asp:TableCell  ForeColor="AliceBlue" Font-Size="Medium">
 <asp:Label ID="Label1" runat="server" ForeColor="White"></asp:Label>
    <asp:Literal ID="Literal1" runat="server" ></asp:Literal>
   
</asp:TableCell>
<asp:TableCell CssClass="UserInfo" ID="UserInfo" HorizontalAlign="Right"></asp:TableCell>
</asp:TableRow>
</asp:Table>
In Header.ascx.cs I add the following details:
  protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                MySqlDataReader dr = objMasBLLogic.Header();
                dr.Read();
                if (dr.HasRows)
                {
                    StringBuilder address = new StringBuilder();
                    address.AppendLine(dr[0].ToString());

                    address.AppendLine(dr[1].ToString());

                    address.AppendLine(dr[2].ToString());

                    address.AppendLine(dr[3].ToString());

                    address.AppendLine(dr[4].ToString());
                    Literal1.Text = address.ToString();

                }
                StringBuilder strLoggedIn = new StringBuilder();
                strLoggedIn.AppendFormat("Logged in as: <span class='UserName'> {0} </span> ", Session["username"]);
                //strLoggedIn.AppendFormat("Logged in as: <span class='UserName'> {0} </span> | ", Session["username"]);
                //strLoggedIn.Append("<A href='mailto:[email protected]'>Contact</A> | ");
                System.Web.UI.WebControls.LinkButton SignOutLink = new System.Web.UI.WebControls.LinkButton();

                System.Web.UI.WebControls.HyperLink HelpLink = new System.Web.UI.WebControls.HyperLink();
                HelpLink.Text = "Help | ";
                HelpLink.ForeColor= Color.White;
                HelpLink.NavigateUrl = "EvHelp.htm";
                HelpLink.Target = "_blank";

                System.Web.UI.WebControls.HyperLink conlink = new System.Web.UI.WebControls.HyperLink();
                conlink.Text = "Contact";
                conlink.ForeColor = Color.White;
                conlink.NavigateUrl = "  mailto:[email protected]  ";
                conlink.Target = "_blank";

                Table HeaderTable = (Table)this.FindControl("tblHeader");
                TableCell UserInfoCell = (TableCell)HeaderTable.Rows[0].FindControl("UserInfo");
                UserInfoCell.Controls.Add(new LiteralControl(strLoggedIn.ToString()));
               // UserInfoCell.Controls.Add(HelpLink);
               // UserInfoCell.Controls.Add(conlink);

            }

        }


Here the problem is,when I run application the "Literal1" control works properly.But the stringbuilder "Logged in as" Can't be displayed properly.When I do action in particular page,the control "Logged in as:" not be displayed..Sometimes only displayed.How I display this all times in my application? Can any one help me to do this?




















Answers (2)