0

I'm trying to create a div in codebehind using an existing div with classes and css styling attached.

The code needs to take variables declared in c#, and generate a div using the existing classes in order to apply the correct styling.

I've tried passing the variables directly to javascript which works, but has a few issues, I've tried using scriptmanager to pass the variables to a javascript function but as soon as I pass more than one variable i get SyntaxError: missing ")".

So i figured the best method would be to create the div in codebehind, but I am yet to find a method that actually works.

Lets say the ideal layout is made up of nested divs.

<div id="main" class="wrapper row-fluid">
        // the divs that need to be generated
        <div class="infoContainer column">
            <h4 class="headText">&nbsp Var1-Var2</h4>

            <div class="innerLeft">
                <img src="Images/placeholder1.png" />
                <p>Var3</p>
                <p>Var4</p>
                <p>Var5</p>
            </div>
            <div class="innerRight">   
                <img src="Images/Placeholder2.png" style="padding-right: 20px;" />
            </div

        </div>
    </div>

and the variables that are declared in code behind, which will be

   var var1;
   var var2;
   var var3;
   var var4;
   var var5;

for now.

Bazilby
  • 79
  • 1
  • 8

1 Answers1

0

did you look in option <%# ... %> or enter link description here also you can use:

private void CreateDiv(string divId)
    {
        HtmlGenericControl div = new HtmlGenericControl("div");
        div.Attributes.Add("id", divId);
        divImage.Controls.Add(div);
    }

to call CreateDiv("div1");

Power Mouse
  • 727
  • 6
  • 16