Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way I can make a div runat server? So i can turn it into a control?

Tags:

html

c#

asp.net

Is there a way I can make a div runat server? So i can turn it into a control? In asp.net?

EDIt:

IF so how can I tell my code below to make div ID=test runat server?

            while (reader.Read())
            {
                System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                div.Attributes["class"] = "test";
        //div.Style["float"] = "left";

                div.ID = "test";
                Image img = new Image();
                img.ImageUrl = String.Format("{0}", reader.GetString(1));
                // this line needs to be represented in sql syntax
                //img.ImageUrl = "~/userdata/2/uploadedimage/batman-for-facebook.jpg";
                img.AlternateText = "Test image";

                div.Controls.Add(img);
                div.Controls.Add(ParseControl(String.Format("&nbsp&nbsp "+"{0}", reader.GetString(0))));
                div.Style["clear"] = "both";
                test1.Controls.Add(div);

            }
like image 623
G Gr Avatar asked Mar 28 '11 18:03

G Gr


People also ask

Why do we add runat server to a web control?

The runat="server" tag in ASP.NET allows the ability to convert/treat most any HTML element as a server-side control that you can manipulate via code at generation time. Some controls have explicit implementations, others simply revert to a generic control implementation.

What is Div control?

The Div control is used to specify a container that groups content into logical sections on Web page. The Div control also enables you to apply CSS (cascading style sheet) rules to content of the control.

Does adding a runat server attribute to an HTML element change anything?

HTML elements in ASP.NET files are, by default, treated as text. To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server control.

What is form runat server?

The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts. In the following example we declare an HtmlAnchor server control in an .aspx file.


1 Answers

You can make a div runat="server", give it an id and the reference it from C# if that's what you're after. However, why not just use an asp:panel, they do the same job essentially and the panel renders a div out in most scenarios

like image 159
Hawxby Avatar answered Sep 25 '22 13:09

Hawxby