nirav patel
nirav patel

Reputation: 465

How to display div with inner text at runtime

I have div as per below example: Now my need is to display Div at runtime without using jquery or javascript .So i would get that.

I need to use only asp.net (c#) :

<div runat="server" id="balancing" style="display:none;">
<div style="width: 330px; height: 30px; float: left;">&nbsp;</div>
<div style="width: 330px; height: 30px; float: left;">&nbsp;</div>
<div style="width: 330px; height: 30px; float: left;"  >
<div style="width: 150px; float: left;"><asp:Label ID="lblBalancing" runat="server" Text="Balancing:" CssClass="label"></asp:Label>
</div>
<div style="width: 150px; float: left;"><asp:TextBox ID="txtBalancing" runat="server" CssClass="input" Enabled="false"></asp:TextBox>
</div>
</div>
</div>

Upvotes: 0

Views: 6156

Answers (4)

user1149002
user1149002

Reputation:

Display:

balancing.Style.Remove(HtmlTextWriterStyle.Display);
balancing.Style.Add(HtmlTextWriterStyle.Display,"Block");

Hide:

balancing.Style.Remove(HtmlTextWriterStyle.Display);
balancing.Style.Add(HtmlTextWriterStyle.Display,"None");

Upvotes: 0

Flatlineato
Flatlineato

Reputation: 1066

Add an asp:Panel set as visible false, on post back make panel visible true. Panel render as a div

Upvotes: 0

Neha
Neha

Reputation: 2965

  1. You can add dynamically an asp.net panel which generates div tag.

    // Create dynamic controls here.
    // Use "using System.Web.UI.WebControls;"
    Panel panel1 = new Panel();
    panel1.ID = "MyPanel";
    Form1.Controls.Add(panel1);
    
  2. Create you div using HtmlGenericControl class

    HtmlGenericControl myDiv = new HtmlGenericControl("div");
    myDiv.ID = "myDiv";
    LinkButton myLnkBtn = new LinkButton();
    myLnkBtn.ID = "myLnkBtn";
    myLnkBtn.Click += new EventHandler(myLnkBtn_Click);
    myLnkBtn.Text = "I'm dynamic";
    myDiv.Controls.Add(myLnkBtn);
    PlaceHolder1.Controls.Add(myDiv);
    

Upvotes: 3

Alex Dn
Alex Dn

Reputation: 5553

You can set style/CssClass for your div in code behide:

balancing.Style[HtmlTextWriterStyle.Display] = "Block";
//or
balancing.Attributes["class"] = "VisibleClass";

Upvotes: 0

Related Questions