Link to home
Start Free TrialLog in
Avatar of eddyperu
eddyperuFlag for United States of America

asked on

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

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
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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
So :


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

Open in new window

Avatar of eddyperu

ASKER

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




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.
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

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

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the points!