how can I add a DIV using the server side(C#)?

eddyperu
eddyperu used Ask the Experts™
on
HI experts:
I am using C#
I need to add this section inside this <DIV id="ContingetFirstBox">....//add here  </DIV>

Section that need to be added to my page
 <div style="float:left;padding-right:60px;">// this is a session text "myName "</div>                                          
 <div style="float:left;padding-right:60px;"><img src="images/primary.png" alt="s" /></div>
  <div style="float:left;">100%</div>
  <div style="clear: both;"></div>

In my C# I have this:
        protected void Page_Load(object sender, EventArgs e)
        {
            String myName = Session["ValueContingent"].ToString();
           // This is where I need to add that section
        }

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
leakim971Multitechnician
Top Expert 2014

Commented:
You have : <DIV id="ContingetFirstBox"></DIV>
Use : ContingetFirstBox.InnerHtml

Check example here  : http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlcontainercontrol.innerhtml.aspx
leakim971Multitechnician
Top Expert 2014

Commented:
So :


protected void Page_Load(object sender, EventArgs e)
{
    String myName = Session["ValueContingent"].ToString();
    ContingetFirstBox.InnerHtml = Server.HtmlEncode(myName);
}

Open in new window

Author

Commented:
Sorry I think it wasn't that clear:

I need to add all this section:
<div style="float:left;padding-right:60px;">//String myName = Session["ValueContingent"].ToString();</div>
 <div style="float:left;padding-right:60px;"><img src="images/primary.png" alt="s" /></div>
  <div style="float:left;">100%</div>
  <div style="clear: both;"></div>


Inside this div :
 <DIV id="ContingetFirstBox" runat="server">  ....</DIV>

Thanks




Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
Perhaps an easier solution is to use a panel (uses div) or placeholder (no div) control which should just be a drag and drop. Then just drop a label or literal control into the panel control. Modify the text property.
leakim971Multitechnician
Top Expert 2014

Commented:
Try :


protected void Page_Load(object sender, EventArgs e)
{
    String myName = Session["ValueContingent"].ToString();
    String ihtml = "<div style=\"float:left;padding-right:60px;\">" + myName;
    ihtml += "</div><div style=\"float:left;padding-right:60px;\"><img src=\"images/primary.png\" alt=\"s\" />";
    ihtml += "</div><div style=\"float:left;\">100%</div><div style=\"clear: both;\"></div>";
    ContingetFirstBox.InnerHtml = ihtml;
}

Open in new window

leakim971Multitechnician
Top Expert 2014

Commented:
Tested, it work :

Page :

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <DIV id="ContingetFirstBox" runat="server"></DIV>
    </div>
    </form>
</body>
</html>

Open in new window

Multitechnician
Top Expert 2014
Commented:
Code behind :


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String myName = "YES";
        String ihtml = "<div style=\"float:left;padding-right:60px;\">" + myName;
        ihtml += "</div><div style=\"float:left;padding-right:60px;\"><img src=\"images/primary.png\" alt=\"s\" />";
        ihtml += "</div><div style=\"float:left;\">100%</div><div style=\"clear: both;\"></div>";
        ContingetFirstBox.InnerHtml = ihtml;
    }
}

Open in new window

leakim971Multitechnician
Top Expert 2014

Commented:
Thanks for the points!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial